<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang xml:lang>
<head>
  <meta charset="utf-8" />
  <meta name="generator" content="pandoc" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" />
  <title>穿山甲Android SDK</title>
  <style type="text/css">
      code{white-space: pre-wrap;}
      span.smallcaps{font-variant: small-caps;}
      span.underline{text-decoration: underline;}
      div.column{display: inline-block; vertical-align: top; width: 50%;}
  </style>
  <style type="text/css">
a.sourceLine { display: inline-block; line-height: 1.25; }
a.sourceLine { pointer-events: none; color: inherit; text-decoration: inherit; }
a.sourceLine:empty { height: 1.2em; }
.sourceCode { overflow: visible; }
code.sourceCode { white-space: pre; position: relative; }
div.sourceCode { margin: 1em 0; }
pre.sourceCode { margin: 0; }
@media screen {
div.sourceCode { overflow: auto; }
}
@media print {
code.sourceCode { white-space: pre-wrap; }
a.sourceLine { text-indent: -1em; padding-left: 1em; }
}
pre.numberSource a.sourceLine
  { position: relative; left: -4em; }
pre.numberSource a.sourceLine::before
  { content: attr(title);
    position: relative; left: -1em; text-align: right; vertical-align: baseline;
    border: none; pointer-events: all; display: inline-block;
    -webkit-touch-callout: none; -webkit-user-select: none;
    -khtml-user-select: none; -moz-user-select: none;
    -ms-user-select: none; user-select: none;
    padding: 0 4px; width: 4em;
    color: #aaaaaa;
  }
pre.numberSource { margin-left: 3em; border-left: 1px solid #aaaaaa;  padding-left: 4px; }
div.sourceCode
  {  }
@media screen {
a.sourceLine::before { text-decoration: underline; }
}
code span.al { color: #ff0000; font-weight: bold; } /* Alert */
code span.an { color: #60a0b0; font-weight: bold; font-style: italic; } /* Annotation */
code span.at { color: #7d9029; } /* Attribute */
code span.bn { color: #40a070; } /* BaseN */
code span.bu { } /* BuiltIn */
code span.cf { color: #007020; font-weight: bold; } /* ControlFlow */
code span.ch { color: #4070a0; } /* Char */
code span.cn { color: #880000; } /* Constant */
code span.co { color: #60a0b0; font-style: italic; } /* Comment */
code span.cv { color: #60a0b0; font-weight: bold; font-style: italic; } /* CommentVar */
code span.do { color: #ba2121; font-style: italic; } /* Documentation */
code span.dt { color: #902000; } /* DataType */
code span.dv { color: #40a070; } /* DecVal */
code span.er { color: #ff0000; font-weight: bold; } /* Error */
code span.ex { } /* Extension */
code span.fl { color: #40a070; } /* Float */
code span.fu { color: #06287e; } /* Function */
code span.im { } /* Import */
code span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Information */
code span.kw { color: #007020; font-weight: bold; } /* Keyword */
code span.op { color: #666666; } /* Operator */
code span.ot { color: #007020; } /* Other */
code span.pp { color: #bc7a00; } /* Preprocessor */
code span.sc { color: #4070a0; } /* SpecialChar */
code span.ss { color: #bb6688; } /* SpecialString */
code span.st { color: #4070a0; } /* String */
code span.va { color: #19177c; } /* Variable */
code span.vs { color: #4070a0; } /* VerbatimString */
code span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warning */
  </style>
  <style type="text/css">
body {
font-family: Helvetica, arial, sans-serif;
font-size: 14px;
line-height: 1.6;
padding-top: 10px;
padding-bottom: 10px;
background-color: white;
padding: 30px; }
body > *:first-child {
margin-top: 0 !important; }
body > *:last-child {
margin-bottom: 0 !important; }
a {
color: #4183C4; }
a.absent {
color: #cc0000; }
a.anchor {
display: block;
padding-left: 30px;
margin-left: -30px;
cursor: pointer;
position: absolute;
top: 0;
left: 0;
bottom: 0; }
h1, h2, h3, h4, h5, h6 {
margin: 20px 0 10px;
padding: 0;
font-weight: bold;
-webkit-font-smoothing: antialiased;
cursor: text;
position: relative; }
h1:hover a.anchor, h2:hover a.anchor, h3:hover a.anchor, h4:hover a.anchor, h5:hover a.anchor, h6:hover a.anchor {
background: url() no-repeat 10px center;
text-decoration: none; }
h1 tt, h1 code {
font-size: inherit; }
h2 tt, h2 code {
font-size: inherit; }
h3 tt, h3 code {
font-size: inherit; }
h4 tt, h4 code {
font-size: inherit; }
h5 tt, h5 code {
font-size: inherit; }
h6 tt, h6 code {
font-size: inherit; }
h1 {
font-size: 28px;
text-align: center;
border-bottom: 1px solid #cccccc;
color: #548DD4; }
h2 {
font-size: 24px; }
h3 {
font-size: 20px;
color: #548DD4; }
h4 {
font-size: 18px; }
h5 {
font-size: 16px;
color: #F79646; }
h6 {
color: #777777;
font-size: 14px; }
p, blockquote, ul, ol, dl, li, table, pre {
font-family: 'lucida grande';
margin: 15px 0; }
hr {
border-bottom: 1px solid;
padding: 0;
background: none repeat scroll 0 0 transparent;
border-color: #DDDDDD;
border-style: none none solid;
border-width: 1px;
clear: both;
height: 0;
margin: 15px 0;
overflow: hidden;
}
body > h2:first-child {
margin-top: 0;
padding-top: 0; }
body > h1:first-child {
margin-top: 0;
padding-top: 0; }
body > h1:first-child + h2 {
margin-top: 0;
padding-top: 0; }
body > h3:first-child, body > h4:first-child, body > h5:first-child, body > h6:first-child {
margin-top: 0;
padding-top: 0; }
a:first-child h1, a:first-child h2, a:first-child h3, a:first-child h4, a:first-child h5, a:first-child h6 {
margin-top: 0;
padding-top: 0; }
h1 p, h2 p, h3 p, h4 p, h5 p, h6 p {
margin-top: 0; }
li p.first {
display: inline-block; }
li {
margin: 0; }
ul, ol {
padding-left: 30px; }
ul :first-child, ol :first-child {
margin-top: 0; }
dl {
padding: 0; }
dl dt {
font-size: 14px;
font-weight: bold;
font-style: italic;
padding: 0;
margin: 15px 0 5px; }
dl dt:first-child {
padding: 0; }
dl dt > :first-child {
margin-top: 0; }
dl dt > :last-child {
margin-bottom: 0; }
dl dd {
margin: 0 0 15px;
padding: 0 15px; }
dl dd > :first-child {
margin-top: 0; }
dl dd > :last-child {
margin-bottom: 0; }
blockquote {
border-left: 4px solid #dddddd;
padding: 0 15px;
color: #777777; }
blockquote > :first-child {
margin-top: 0; }
blockquote > :last-child {
margin-bottom: 0; }
table {
padding: 0;border-collapse: collapse; }
table tr {
border-top: 1px solid #cccccc;
background-color: white;
margin: 0;
padding: 0; }
table tr:nth-child(2n) {
background-color: #f8f8f8; }
table tr th {
font-weight: bold;
border: 1px solid #cccccc;
margin: 0;
padding: 6px 13px; }
table tr td {
border: 1px solid #cccccc;
margin: 0;
padding: 6px 13px; }
table tr th :first-child, table tr td :first-child {
margin-top: 0; }
table tr th :last-child, table tr td :last-child {
margin-bottom: 0; }
img {
max-width: 100%; }
span.frame {
display: block;
overflow: hidden; }
span.frame > span {
border: 1px solid #dddddd;
display: block;
float: left;
overflow: hidden;
margin: 13px 0 0;
padding: 7px;
width: auto; }
span.frame span img {
display: block;
float: left; }
span.frame span span {
clear: both;
color: #333333;
display: block;
padding: 5px 0 0; }
span.align-center {
display: block;
overflow: hidden;
clear: both; }
span.align-center > span {
display: block;
overflow: hidden;
margin: 13px auto 0;
text-align: center; }
span.align-center span img {
margin: 0 auto;
text-align: center; }
span.align-right {
display: block;
overflow: hidden;
clear: both; }
span.align-right > span {
display: block;
overflow: hidden;
margin: 13px 0 0;
text-align: right; }
span.align-right span img {
margin: 0;
text-align: right; }
span.float-left {
display: block;
margin-right: 13px;
overflow: hidden;
float: left; }
span.float-left span {
margin: 13px 0 0; }
span.float-right {
display: block;
margin-left: 13px;
overflow: hidden;
float: right; }
span.float-right > span {
display: block;
overflow: hidden;
margin: 13px auto 0;
text-align: right; }
code, tt {
margin: 0 2px;
padding: 0 5px;
white-space: nowrap;
border: 1px solid #eaeaea;
background-color: #f8f8f8;
border-radius: 3px; }
pre code {
margin: 0;
padding: 0;
white-space: pre;
border: none;
background: transparent; }
.highlight pre {
background-color: #f8f8f8;
border: 1px solid #cccccc;
font-size: 13px;
line-height: 19px;
overflow: auto;
padding: 6px 10px;
border-radius: 3px; }
pre {
background-color: #f8f8f8;
border: 1px solid #cccccc;
font-size: 13px;
line-height: 19px;
overflow: auto;
padding: 6px 10px;
border-radius: 3px; }
pre code, pre tt {
background-color: transparent;
border: none; }
sup {
font-size: 0.83em;
vertical-align: super;
line-height: 0;
}
* {
-webkit-print-color-adjust: exact;
}
@media screen and (min-width: 914px) {
body {
width: 854px;
margin:0 auto;
}
}
@media print {
table, pre {
page-break-inside: avoid;
}
pre {
word-wrap: break-word;
}
}
</style>
  <!--[if lt IE 9]>
    <script src="//cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.3/html5shiv-printshiv.min.js"></script>
  <![endif]-->
</head>
<body>
<nav id="TOC">
<ul>
<li><a href="#穿山甲android-sdk接入说明文档">穿山甲Android SDK——接入说明文档</a><ul>
<li><a href="#sdk接入">1.SDK接入</a><ul>
<li><a href="#sdk包的导入">1.1SDK包的导入</a><ul>
<li><a href="#申请应用的codeid">1.1.1申请应用的CodeId</a></li>
<li><a href="#导入aar及sdk依赖的jar包">1.1.2 导入aar及SDK依赖的jar包</a></li>
</ul></li>
<li><a href="#androidmanifest配置">1.2 AndroidManifest配置</a><ul>
<li><a href="#添加权限">1.2.1 添加权限</a></li>
<li><a href="#适配anroid7.0及以上">1.2.2 适配Anroid7.0及以上</a></li>
<li><a href="#provider配置">1.2.3 provider配置</a></li>
<li><a href="#运行环境配置">1.2.4 运行环境配置</a></li>
</ul></li>
<li><a href="#代码混淆">1.3 代码混淆</a></li>
<li><a href="#初始化sdk">1.4 初始化SDK</a><ul>
<li><a href="#初始化接口说明">1.4.1 初始化接口说明</a></li>
<li><a href="#初始化配置参数说明">1.4.2 初始化配置参数说明：</a></li>
<li><a href="#隐私信息控制开关">1.4.3 隐私信息控制开关</a></li>
</ul></li>
</ul></li>
<li><a href="#加载广告">2.加载广告</a><ul>
<li><a href="#构建ttadmanager对象">2.1 构建TTAdManager对象 :</a></li>
<li><a href="#构建ttadnative对象">2.2 构建TTAdNative对象</a></li>
<li><a href="#构建adslot对象">2.3 构建AdSlot对象</a></li>
<li><a href="#接入原生信息流广告ttfeedad">2.4 接入原生信息流广告（TTFeedAd）</a><ul>
<li><a href="#ttfeedad接口说明">2.4.1 TTFeedAd接口说明</a></li>
<li><a href="#加载原生信息流广告">2.4.2 加载原生信息流广告</a></li>
<li><a href="#原生信息流视频广告回调">2.4.3 原生信息流视频广告回调</a></li>
<li><a href="#注册可点击的view">2.4.4 注册可点击的View</a></li>
</ul></li>
<li><a href="#接入banner广告ttbannerad">2.5 接入Banner广告（TTBannerAd）</a><ul>
<li><a href="#ttbanner广告接口说明">2.5.1 TTBanner广告接口说明</a></li>
<li><a href="#加载banner广告">2.5.2 加载Banner广告</a></li>
</ul></li>
<li><a href="#接入开屏广告ttsplashad">2.6 接入开屏广告（TTSplashAd）</a><ul>
<li><a href="#ttsplashad广告接口说明">2.6.1 TTSplashAd广告接口说明：</a></li>
<li><a href="#加载开屏广告">2.6.2 加载开屏广告</a></li>
</ul></li>
<li><a href="#接入插屏广告ttinteractionad">2.7 接入插屏广告（TTInteractionAd）</a><ul>
<li><a href="#ttinteractionad接口说明">2.7.1 TTInteractionAd接口说明：</a></li>
<li><a href="#加载插屏广告">2.7.2 加载插屏广告</a></li>
<li><a href="#展示插屏广告">2.7.3 展示插屏广告</a></li>
</ul></li>
<li><a href="#接入原生广告ttnativead">2.8 接入原生广告（TTNativeAd）</a><ul>
<li><a href="#ttnativead接口说明">2.8.1 TTNativeAd接口说明：</a></li>
<li><a href="#加载原生广告">2.8.2 加载原生广告</a></li>
<li><a href="#展示原生广告">2.8.3 展示原生广告</a></li>
</ul></li>
<li><a href="#接入激励视频广告ttrewardvideoad">2.9 接入激励视频广告（TTRewardVideoAd）</a><ul>
<li><a href="#ttrewardvideoad接口说明">2.9.1 TTRewardVideoAd接口说明：</a></li>
<li><a href="#加载激励视频广告">2.9.2 加载激励视频广告</a></li>
<li><a href="#展示视频广告">2.9.3 展示视频广告</a></li>
<li><a href="#服务器到服务器回调">2.9.4 服务器到服务器回调</a><ul>
<li><a href="#回调方式说明">回调方式说明</a></li>
<li><a href="#签名生成方式">签名生成方式</a></li>
<li><a href="#返回约定">返回约定</a></li>
</ul></li>
</ul></li>
<li><a href="#接入全屏视频广告ttfullscreenvideoad">2.10 接入全屏视频广告（TTFullScreenVideoAd）</a><ul>
<li><a href="#ttfullscreenvideoad接口说明">2.10.1 TTFullScreenVideoAd接口说明：</a></li>
<li><a href="#加载全屏视频广告">2.10.2 加载全屏视频广告</a></li>
<li><a href="#展示视频广告-1">2.10.3 展示视频广告</a></li>
</ul></li>
<li><a href="#接入draw竖版视频信息流广告ttdrawfeedad">2.11 接入Draw竖版视频信息流广告（TTDrawFeedAd）</a><ul>
<li><a href="#ttdrawfeedad接口说明">2.11.1 TTDrawFeedAd接口说明：</a></li>
<li><a href="#加载draw竖版视频信息流广告">2.11.2 加载Draw竖版视频信息流广告</a></li>
<li><a href="#展示视频广告-2">2.11.3 展示视频广告</a></li>
</ul></li>
<li><a href="#接入个性化模板信息流广告ttnativeexpressad">2.12 接入个性化模板信息流广告（TTNativeExpressAd）</a><ul>
<li><a href="#ttnativeexpressad接口说明">2.12.1 TTNativeExpressAd接口说明：</a></li>
<li><a href="#加载个性化模板信息流广告绑定接口回调dislike逻辑">2.12.2 加载个性化模板信息流广告，绑定接口回调、dislike逻辑</a></li>
<li><a href="#展示个性化模板信息流广告">2.12.3 展示个性化模板信息流广告</a></li>
</ul></li>
<li><a href="#接入个性化模板banner广告接口同-ttnativeexpressad">2.13 接入个性化模板Banner广告（接口同 TTNativeExpressAd）</a><ul>
<li><a href="#加载个性化模板banner广告绑定接口回调dislike逻辑">2.13.1 加载个性化模板Banner广告，绑定接口回调、dislike逻辑</a></li>
<li><a href="#展示个性化模板banner广告">2.13.2 展示个性化模板Banner广告</a></li>
</ul></li>
<li><a href="#接入个性化模板插屏广告接口同-ttnativeexpressad">2.14 接入个性化模板插屏广告（接口同 TTNativeExpressAd）</a><ul>
<li><a href="#加载个性化模板插屏广告绑定接口回调">2.14.1 加载个性化模板插屏广告，绑定接口回调</a></li>
<li><a href="#展示个性化模板插屏广告">2.14.2 展示个性化模板插屏广告</a></li>
</ul></li>
<li><a href="#接入个性化模板draw视频广告接口同-ttnativeexpressad">2.15 接入个性化模板Draw视频广告（接口同 TTNativeExpressAd）</a><ul>
<li><a href="#加载个性化模板draw视频广告绑定接口回调">2.15.1 加载个性化模板Draw视频广告，绑定接口回调</a></li>
<li><a href="#展示个性化模板draw视频广告">2.15.2 展示个性化模板Draw视频广告</a></li>
</ul></li>
<li><a href="#下载监听器注册">2.16 下载监听器注册：</a><ul>
<li><a href="#下载监听回调说明">2.16.1 下载监听回调说明</a></li>
<li><a href="#注册下载监听器">2.16.2 注册下载监听器</a></li>
</ul></li>
<li><a href="#feed广告下载状态控制器">2.17 Feed广告下载状态控制器</a><ul>
<li><a href="#feed广告下载状态控制器接口说明">2.17.1 Feed广告下载状态控制器接口说明</a></li>
<li><a href="#接入feed广告app下载状态控制器">2.17.2 接入Feed广告App下载状态控制器</a></li>
<li><a href="#全局下载状态控制器已废弃">2.17.3 全局下载状态控制器（已废弃）</a></li>
<li><a href="#全局下载状态控制器接口说明已废弃">2.17.4 全局下载状态控制器接口说明（已废弃）</a></li>
<li><a href="#接入全局下载状态控制器已废弃">2.17.5 接入全局下载状态控制器（已废弃）</a></li>
<li><a href="#全局下载状态监听器已废弃">2.17.6 全局下载状态监听器（已废弃）</a></li>
<li><a href="#全局下载状态监听器接口说明已废弃">2.17.7 全局下载状态监听器接口说明（已废弃）</a></li>
<li><a href="#接入全局下载状态监听器已废弃">2.17.8 接入全局下载状态监听器（已废弃）</a></li>
<li><a href="#下载状态module已废弃">2.17.9 下载状态Module（已废弃）</a></li>
</ul></li>
<li><a href="#接入dislike逻辑ttaddislike">3.0 接入Dislike逻辑（TTAdDislike）</a><ul>
<li><a href="#ttaddislike接口说明">3.1 TTAdDislike接口说明</a></li>
<li><a href="#信息流广告接入dislike">3.2 信息流广告接入Dislike</a></li>
<li><a href="#banner广告接入dislike">3.3 Banner广告接入Dislike</a></li>
<li><a href="#自定义dislike对话框使用说明">3.4 自定义dislike对话框使用说明</a></li>
</ul></li>
</ul></li>
<li><a href="#参考">4.参考</a><ul>
<li><a href="#sdk错误码">4.1 SDK错误码</a></li>
<li><a href="#sdk多进程支持">4.2 SDK多进程支持</a></li>
<li><a href="#sdk打包为独立插件">4.3 SDK打包为独立插件</a></li>
<li><a href="#主题配置">4.4 主题配置</a><ul>
<li><a href="#下载删除弹窗主题配置">4.4.1 下载删除弹窗主题配置</a></li>
<li><a href="#落地页titlebar主题配置">4.4.2 落地页titleBar主题配置</a></li>
</ul></li>
<li><a href="#常见问题">4.5 常见问题</a></li>
</ul></li>
</ul></li>
</ul>
</nav>
<h1 id="穿山甲android-sdk接入说明文档">穿山甲Android SDK——接入说明文档</h1>
<table>
<colgroup>
<col style="width: 33%"></col>
<col style="width: 33%"></col>
<col style="width: 33%"></col>
</colgroup>
<thead>
<tr class="header">
<th>文档版本</th>
<th>修订日期</th>
<th>修订说明</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td>v1.0.0</td>
<td>2017-06-23</td>
<td>创建文档，支持Banner，信息流广告</td>
</tr>
<tr class="even">
<td>v1.1.0</td>
<td>2017-07-21</td>
<td>优化接口字段，数据加密</td>
</tr>
<tr class="odd">
<td>v1.1.1</td>
<td>2017-07-30</td>
<td>优化事件回调接口</td>
</tr>
<tr class="even">
<td>v1.2.0</td>
<td>2017-09-17</td>
<td>新增开屏、插屏广告</td>
</tr>
<tr class="odd">
<td>v1.3.0</td>
<td>2017-09-24</td>
<td>支持开屏、插屏广告和广告dislike；增加banner、信息流广告的回调接口，及用户广告反馈接口；</td>
</tr>
<tr class="even">
<td>v1.3.1</td>
<td>2017-10-27</td>
<td>解决了特殊情况下会crash的问题；对image_mode字段进行优化</td>
</tr>
<tr class="odd">
<td>v1.3.2</td>
<td>2017-11-08</td>
<td>增加全局配置是否允许SDK弹出通知、落地页出现在锁屏上面，增加全局下载器。</td>
</tr>
<tr class="even">
<td>v1.4.0</td>
<td>2017-12-08</td>
<td>支持更多广告类型的投放；优化了应用下载广告通知栏状态和交互；提升开屏广告接入灵活性</td>
</tr>
<tr class="odd">
<td>v1.5.0</td>
<td>2018-01-08</td>
<td>新增banner轮播，视频广告</td>
</tr>
<tr class="even">
<td>v1.6.0</td>
<td>2018-01-31</td>
<td>添加logo,支持应用调起广告，优化UI和交互等</td>
</tr>
<tr class="odd">
<td>v1.7.0</td>
<td>2018-02-08</td>
<td>新增激励视频广告，新增激励视频接入说明</td>
</tr>
<tr class="even">
<td>v1.8.0</td>
<td>2018-04-03</td>
<td>激励视频纵向支持与横向展示，插屏等样式修改，新增部分回调接口，下载相关问题修复</td>
</tr>
<tr class="odd">
<td>v1.8.1</td>
<td>2018-04-12</td>
<td>数据埋点优化，广告落地页问题修复</td>
</tr>
<tr class="even">
<td>v1.9.0</td>
<td>2018-04-25</td>
<td>开屏广告逻辑优化，部分已知问题修复</td>
</tr>
<tr class="odd">
<td>v1.9.1</td>
<td>2018-05-24</td>
<td>提升展示率，适配部分机型</td>
</tr>
<tr class="even">
<td>v1.9.2</td>
<td>2018-05-31</td>
<td>信息流视频广告逻辑优化</td>
</tr>
<tr class="odd">
<td>v1.9.3</td>
<td>2018-06-12</td>
<td>锁屏场景广告适配以及部分已知问题的修复</td>
</tr>
<tr class="even">
<td>v1.9.3.1</td>
<td>2018-07-08</td>
<td>信息流视频广告性能优化</td>
</tr>
<tr class="odd">
<td>v1.9.3.2</td>
<td>2018-07-13</td>
<td>展示条件中广告宽高大于50像素，性能优化</td>
</tr>
<tr class="even">
<td>v1.9.4</td>
<td>2018-07-16</td>
<td>信息流视频广告优化以及管理后台新增视频自动播放和静音设置选项</td>
</tr>
<tr class="odd">
<td>v1.9.5</td>
<td>2018-08-31</td>
<td>视频广告增加TextureView支持、新增全屏视频类型广告、新增原生广告支持、优化广告下载模块及其他已知问题修复等 <br>TTDownloadProvider删除，全局监听暂时不可用，混淆规则变更</br><br>取消全局下载控制和监听器功能</br></td>
</tr>
<tr class="even">
<td>v1.9.6</td>
<td>2018-09-13</td>
<td>优化埋点信息，R资源访问方式更改，已知问题修复</td>
</tr>
<tr class="odd">
<td>v1.9.6.1</td>
<td>2018-09-26</td>
<td>优化内存使用和电量使用，修复已知问题</td>
</tr>
<tr class="even">
<td>v1.9.7</td>
<td>2018-10-22</td>
<td>视频广告缓存逻辑优化，新增Draw信息流广告</td>
</tr>
<tr class="odd">
<td>v1.9.7.1</td>
<td>2018-11-07</td>
<td>修复资源文件命名冲突问题</td>
</tr>
<tr class="even">
<td>v1.9.7.2</td>
<td>2018-11-21</td>
<td>优化落地页广告体验，修复低概率异常，增强稳定性</td>
</tr>
<tr class="odd">
<td>v1.9.8</td>
<td>2018-12-06</td>
<td>多进程使用环境支持</td>
</tr>
<tr class="even">
<td>v1.9.9</td>
<td>2019-01-10</td>
<td>视频场景优化、激励视频样式优化、dislike自定义支持</td>
</tr>
<tr class="odd">
<td>v2.0.1.0</td>
<td>2019-03-05</td>
<td>支持原生动态布局，激励视频样式优化，已知bug修复</td>
</tr>
<tr class="even">
<td>v2.1.0.0</td>
<td>2019-05-14</td>
<td>提升视频广告播放体验，对外提供回调事件完善，已知问题修复</td>
</tr>
<tr class="odd">
<td>v2.2.0.0</td>
<td>2019-06-17</td>
<td>开屏支持视频广告，新增激励视频广告样式</td>
</tr>
<tr class="even">
<td>v2.3.0.0</td>
<td>2019-07-17</td>
<td>原生广告支持试玩广告，激励视频广告样式优化</td>
</tr>
<tr class="odd">
<td>v2.3.0.1</td>
<td>2019-07-18</td>
<td>完善个性化模板广告</td>
</tr>
<tr class="even">
<td>v2.4.0.0</td>
<td>2019-08-23</td>
<td>完善试玩广告场景，优化启动速度</td>
</tr>
<tr class="odd">
<td>v2.4.1.1</td>
<td>2019-09-06</td>
<td>增加个性化模板视频广告场景</td>
</tr>
<tr class="even">
<td>v2.4.1.2</td>
<td>2019-09-29</td>
<td>适配安卓Q</td>
</tr>
<tr class="odd">
<td>v2.4.2.0</td>
<td>2019-10-15</td>
<td>优化开屏广告场景</td>
</tr>
<tr class="even">
<td>v2.5.2.0</td>
<td>2019-10-29</td>
<td>修复已知问题</td>
</tr>
<tr class="odd">
<td>v2.5.2.4</td>
<td>2019-11-01</td>
<td>修复请求广告校验40025问题</td>
</tr>
<tr class="even">
<td>v2.7.0.0</td>
<td>2019-11-26</td>
<td>开屏场景支持个性化模板广告，开屏逻辑优化</td>
</tr>
<tr class="odd">
<td>v2.7.5.0</td>
<td>2019-12-25</td>
<td>优化权限使用和隐私加强，修复已知问题</td>
</tr>
<tr class="even">
<td>v2.7.5.1</td>
<td>2019-12-27</td>
<td>模板开屏广告点击回调修复</td>
</tr>
<tr class="odd">
<td>v2.8.0.0</td>
<td>2020-01-05</td>
<td>优化广告转化，支持网络容灾</td>
</tr>
<tr class="even">
<td>v2.8.0.1</td>
<td>2020-01-20</td>
<td>优化多进程回调，修复落地页展示问题</td>
</tr>
<tr class="odd">
<td>v2.8.0.2</td>
<td>2020-02-14</td>
<td>广告页面启动逻辑优化</td>
</tr>
<tr class="even">
<td>v2.9.0.0</td>
<td>2020-02-20</td>
<td>模板广告优化</td>
</tr>
<tr class="odd">
<td>v2.9.5.0</td>
<td>2020-03-16</td>
<td>模板广告渲染优化，网络库优化</td>
</tr>
<tr class="even">
<td>v3.1.0.0</td>
<td>2020-06-02</td>
<td>优化广告转化链路，提升转化</td>
</tr>
</tbody>
</table>
<p>[TOC]</p>
<h2 id="sdk接入">1.SDK接入</h2>
<h3 id="sdk包的导入">1.1SDK包的导入</h3>
<h4 id="申请应用的codeid">1.1.1申请应用的CodeId</h4>
<p>请在穿山甲平台上创建好应用ID和广告位ID。</p>
<h4 id="导入aar及sdk依赖的jar包">1.1.2 导入aar及SDK依赖的jar包</h4>
<p>将本SDK压缩包内的open_ad_sdk.aar复制到Application Module/libs文件夹(没有的话须手动创建), 并将以下代码添加到您app的build.gradle中：</p>
<pre><code>repositories {
    flatDir {
        dirs &#39;libs&#39;
    }
}
depedencies {
    compile(name: &#39;open_ad_sdk&#39;, ext: ‘aar&#39;)
}
</code></pre>
<h3 id="androidmanifest配置">1.2 AndroidManifest配置</h3>
<h4 id="添加权限">1.2.1 添加权限</h4>
<pre><code>&lt;!--必要权限--&gt;
&lt;uses-permission android:name=&quot;android.permission.INTERNET&quot; /&gt;

&lt;!--可选权限--&gt;
&lt;uses-permission android:name=&quot;android.permission.READ_PHONE_STATE&quot; /&gt;
&lt;uses-permission android:name=&quot;android.permission.ACCESS_NETWORK_STATE&quot; /&gt;
&lt;uses-permission android:name=&quot;android.permission.WRITE_EXTERNAL_STORAGE&quot; /&gt;
&lt;uses-permission android:name=&quot;android.permission.ACCESS_WIFI_STATE&quot; /&gt;
&lt;uses-permission android:name=&quot;android.permission.ACCESS_COARSE_LOCATION&quot; /&gt;
&lt;uses-permission android:name=&quot;android.permission.REQUEST_INSTALL_PACKAGES&quot;/&gt;
&lt;uses-permission android:name=&quot;android.permission.GET_TASKS&quot;/&gt;

&lt;!--可选，穿山甲提供“获取地理位置权限”和“不给予地理位置权限，开发者传入地理位置参数”两种方式上报用户位置，两种方式均可不选，添加位置权限或参数将帮助投放定位广告--&gt;
&lt;!--请注意：无论通过何种方式提供给穿山甲用户地理位置，均需向用户声明地理位置权限将应用于穿山甲广告投放，穿山甲不强制获取地理位置信息--&gt;
&lt;uses-permission android:name=&quot;android.permission.ACCESS_FINE_LOCATION&quot; /&gt;

&lt;!-- 如果有视频相关的广告且使用textureView播放，请务必添加，否则黑屏 --&gt;
&lt;uses-permission android:name=&quot;android.permission.WAKE_LOCK&quot; /&gt;
</code></pre>
<p><strong>注意</strong>: 穿山甲SDK不强制获取以上权限，即使没有获取可选权限SDK也能正常运行；获取以上权限将帮助穿山甲优化投放广告精准度和用户的交互体验，提高eCPM。</p>
<div class="sourceCode" id="cb3"><pre class="sourceCode java"><code class="sourceCode java"><a class="sourceLine" id="cb3-1" title="1"><span class="co">//建议在广告请求前，合适的时机调用SDK提供的方法</span></a>
<a class="sourceLine" id="cb3-2" title="2"><span class="co">//TTAdManager接口中的方法，context可以是Activity或Application</span></a>
<a class="sourceLine" id="cb3-3" title="3"><span class="dt">void</span> <span class="fu">requestPermissionIfNecessary</span>(<span class="bu">Context</span> context);</a></code></pre></div>
<h4 id="适配anroid7.0及以上">1.2.2 适配Anroid7.0及以上</h4>
<p>如果您的应用需要在Anroid7.0及以上环境运行，请在AndroidManifest中添加如下代码：</p>
<pre><code>&lt;provider
    android:name=&quot;com.bytedance.sdk.openadsdk.TTFileProvider&quot;
    android:authorities=&quot;${applicationId}.TTFileProvider&quot;
    android:exported=&quot;false&quot;
    android:grantUriPermissions=&quot;true&quot;&gt;
   &lt;meta-data
        android:name=&quot;android.support.FILE_PROVIDER_PATHS&quot;
        android:resource=&quot;@xml/file_paths&quot; /&gt;
&lt;/provider&gt;</code></pre>
<p>在res/xml目录下，新建一个xml文件file_paths，在该文件中添加如下代码：</p>
<pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;paths xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;&gt;
   &lt;!--为了适配所有路径可以设置 path = &quot;.&quot; --&gt;
     &lt;external-path name=&quot;tt_external_root&quot; path=&quot;.&quot; /&gt;
   &lt;external-path name=&quot;tt_external_download&quot; path=&quot;Download&quot; /&gt;
   &lt;external-files-path name=&quot;tt_external_files_download&quot; path=&quot;Download&quot; /&gt;
   &lt;files-path name=&quot;tt_internal_file_download&quot; path=&quot;Download&quot; /&gt;
   &lt;cache-path name=&quot;tt_internal_cache_download&quot; path=&quot;Download&quot; /&gt;
&lt;/paths&gt;</code></pre>
<pre><code>为了适配下载和安装相关功能，在工程中引用的包 com.android.support:support-v4:24.2.0
使用24.2.0以及以上版本。</code></pre>
<h4 id="provider配置">1.2.3 provider配置</h4>
<p><strong>注意</strong>：单进程或多进程都必须配置</p>
<div class="sourceCode" id="cb7"><pre class="sourceCode xml"><code class="sourceCode xml"><a class="sourceLine" id="cb7-1" title="1"><span class="kw">&lt;provider</span></a>
<a class="sourceLine" id="cb7-2" title="2"><span class="ot">    android:name=</span><span class="st">&quot;com.bytedance.sdk.openadsdk.multipro.TTMultiProvider&quot;</span></a>
<a class="sourceLine" id="cb7-3" title="3"><span class="ot">    android:authorities=</span><span class="st">&quot;${applicationId}.TTMultiProvider&quot;</span></a>
<a class="sourceLine" id="cb7-4" title="4"><span class="ot">    android:exported=</span><span class="st">&quot;false&quot;</span> <span class="kw">/&gt;</span></a></code></pre></div>
<h4 id="运行环境配置">1.2.4 运行环境配置</h4>
<p>本SDK可运行于Android4.0 (API Level 14) 及以上版本。</p>
<div class="sourceCode" id="cb8"><pre class="sourceCode xml"><code class="sourceCode xml"><a class="sourceLine" id="cb8-1" title="1"><span class="kw">&lt;uses-sdk</span><span class="ot"> android:minSdkVersion=</span><span class="st">&quot;14&quot;</span><span class="ot"> android:targetSdkVersion=</span><span class="st">&quot;24&quot;</span> <span class="kw">/&gt;</span></a></code></pre></div>
<p>如果开发者声明targetSdkVersion到API 23以上，请确保调用本SDK的任何接口前，已经申请到了SDK要求的所有权限，否则SDK部分特性可能受限。</p>
<h3 id="代码混淆">1.3 代码混淆</h3>
<p>如果您需要使用proguard混淆代码，需确保不要混淆SDK的代码。 请在proguard.cfg文件(或其他混淆文件)尾部添加如下配置:</p>
<pre><code>-keep class com.bytedance.sdk.openadsdk.** { *; }
-keep public interface com.bytedance.sdk.openadsdk.downloadnew.** {*;}
-keep class com.pgl.sys.ces.* {*;}
</code></pre>
<p><strong>注意</strong>: SDK代码被混淆后会导致广告无法展现或者其它异常。</p>
<p><strong>注意</strong>: SDK中使用的so文件支持五种架构：x86,x86_64,armeabi,armeabi-v7a,arm64-v8a 如果您应用中支持的架构超出这 五种，请在build.gradle中使用abiFilters选择支持的架构。如下所示： ndk { // 设置支持的 SO 库构架，注意这里要根据你的实际情况来设置 abiFilters ‘armeabi-v7a’, ‘arm64-v8a’, ‘x86’, ‘x86_64’, ‘armeabi’ }</p>
<h3 id="初始化sdk">1.4 初始化SDK</h3>
<p>开发者需要在Application#onCreate()方法中调用以下代码来初始化穿山甲sdk。 目前sdk已支持多进程，如果明确某个进程不会使用到广告SDK，可以只针对特定进程初始化广告sdk</p>
<div class="sourceCode" id="cb10"><pre class="sourceCode java"><code class="sourceCode java"><a class="sourceLine" id="cb10-1" title="1"><span class="kw">public</span> <span class="kw">class</span> DemoApplication <span class="kw">extends</span> Application {</a>
<a class="sourceLine" id="cb10-2" title="2">    <span class="kw">public</span> <span class="dt">static</span> <span class="bu">String</span> PROCESS_NAME_XXXX = <span class="st">&quot;process_name_xxxx&quot;</span>;</a>
<a class="sourceLine" id="cb10-3" title="3"></a>
<a class="sourceLine" id="cb10-4" title="4">    <span class="at">@Override</span></a>
<a class="sourceLine" id="cb10-5" title="5">    <span class="kw">public</span> <span class="dt">void</span> <span class="fu">onCreate</span>() {</a>
<a class="sourceLine" id="cb10-6" title="6">        <span class="kw">super</span>.<span class="fu">onCreate</span>();</a>
<a class="sourceLine" id="cb10-7" title="7"></a>
<a class="sourceLine" id="cb10-8" title="8">        <span class="co">//强烈建议在应用对应的Application#onCreate()方法中调用，避免出现content为null的异常</span></a>
<a class="sourceLine" id="cb10-9" title="9">        TTAdSdk.<span class="fu">init</span>(context,</a>
<a class="sourceLine" id="cb10-10" title="10">                            <span class="kw">new</span> TTAdConfig.<span class="fu">Builder</span>()</a>
<a class="sourceLine" id="cb10-11" title="11">                                    .<span class="fu">appId</span>(<span class="st">&quot;5001121&quot;</span>)</a>
<a class="sourceLine" id="cb10-12" title="12">                                    .<span class="fu">useTextureView</span>(<span class="kw">false</span>) <span class="co">//使用TextureView控件播放视频,默认为SurfaceView,当有SurfaceView冲突的场景，可以使用TextureView</span></a>
<a class="sourceLine" id="cb10-13" title="13">                                    .<span class="fu">appName</span>(<span class="st">&quot;APP测试媒体&quot;</span>)</a>
<a class="sourceLine" id="cb10-14" title="14">                                    .<span class="fu">titleBarTheme</span>(TTAdConstant.<span class="fu">TITLE_BAR_THEME_DARK</span>)</a>
<a class="sourceLine" id="cb10-15" title="15">                                    .<span class="fu">allowShowNotify</span>(<span class="kw">true</span>) <span class="co">//是否允许sdk展示通知栏提示</span></a>
<a class="sourceLine" id="cb10-16" title="16">                                    .<span class="fu">allowShowPageWhenScreenLock</span>(<span class="kw">true</span>) <span class="co">//是否在锁屏场景支持展示广告落地页</span></a>
<a class="sourceLine" id="cb10-17" title="17">                                    .<span class="fu">debug</span>(<span class="kw">true</span>) <span class="co">//测试阶段打开，可以通过日志排查问题，上线时去除该调用</span></a>
<a class="sourceLine" id="cb10-18" title="18">                                    .<span class="fu">directDownloadNetworkType</span>(TTAdConstant.<span class="fu">NETWORK_STATE_WIFI</span>, TTAdConstant.<span class="fu">NETWORK_STATE_3G</span>) <span class="co">//允许直接下载的网络状态集合</span></a>
<a class="sourceLine" id="cb10-19" title="19">                                    .<span class="fu">supportMultiProcess</span>(<span class="kw">false</span>) <span class="co">//是否支持多进程，true支持</span></a>
<a class="sourceLine" id="cb10-20" title="20">                                    <span class="co">//.httpStack(new MyOkStack3())//自定义网络库，demo中给出了okhttp3版本的样例，其余请自行开发或者咨询工作人员。</span></a>
<a class="sourceLine" id="cb10-21" title="21">                                    .<span class="fu">build</span>());</a>
<a class="sourceLine" id="cb10-22" title="22"></a>
<a class="sourceLine" id="cb10-23" title="23">        <span class="co">//如果明确某个进程不会使用到广告SDK，可以只针对特定进程初始化广告SDK的content</span></a>
<a class="sourceLine" id="cb10-24" title="24">        <span class="co">//if (PROCESS_NAME_XXXX.equals(processName)) {</span></a>
<a class="sourceLine" id="cb10-25" title="25">        <span class="co">//   TTAdSdk.init(context, config);</span></a>
<a class="sourceLine" id="cb10-26" title="26">        <span class="co">//}</span></a>
<a class="sourceLine" id="cb10-27" title="27">    }</a>
<a class="sourceLine" id="cb10-28" title="28">}</a></code></pre></div>
<h4 id="初始化接口说明">1.4.1 初始化接口说明</h4>
<div class="sourceCode" id="cb11"><pre class="sourceCode java"><code class="sourceCode java"><a class="sourceLine" id="cb11-1" title="1">    <span class="co">/**</span></a>
<a class="sourceLine" id="cb11-2" title="2">     <span class="co">*</span> 穿山甲sdk初始化入口</a>
<a class="sourceLine" id="cb11-3" title="3">     <span class="co">*</span></a>
<a class="sourceLine" id="cb11-4" title="4">     <span class="co">* </span><span class="an">@param context </span>必须是application context</a>
<a class="sourceLine" id="cb11-5" title="5">     <span class="co">*</span> <span class="an">@param config </span> 初始化配置信息，必要参数</a>
<a class="sourceLine" id="cb11-6" title="6">     <span class="co">*</span> <span class="an">@return </span>TTAdManager实例</a>
<a class="sourceLine" id="cb11-7" title="7">     <span class="co">*/</span></a>
<a class="sourceLine" id="cb11-8" title="8">    <span class="kw">public</span> <span class="dt">static</span> TTAdManager <span class="fu">init</span>(<span class="bu">Context</span> context, TTAdConfig config);</a></code></pre></div>
<h4 id="初始化配置参数说明">1.4.2 初始化配置参数说明：</h4>
<div class="sourceCode" id="cb12"><pre class="sourceCode java"><code class="sourceCode java"><a class="sourceLine" id="cb12-1" title="1">    <span class="kw">public</span> <span class="dt">static</span> <span class="kw">class</span> TTAdConfig.<span class="fu">Builder</span> {</a>
<a class="sourceLine" id="cb12-2" title="2">        <span class="kw">private</span> <span class="bu">String</span> mAppId;<span class="co">// 必选参数，设置应用的AppId</span></a>
<a class="sourceLine" id="cb12-3" title="3">        <span class="kw">private</span> <span class="bu">String</span> mAppName;<span class="co">// 必选参数，设置应用名称</span></a>
<a class="sourceLine" id="cb12-4" title="4">        <span class="kw">private</span> <span class="dt">boolean</span> mIsPaid = <span class="kw">false</span>;<span class="co">// 可选参数，设置是否为计费用户：true计费用户、false非计费用户。默认为false非计费用户。须征得用户同意才可传入该参数</span></a>
<a class="sourceLine" id="cb12-5" title="5">        <span class="kw">private</span> <span class="bu">String</span> mKeywords;<span class="co">// 可选参数，设置用户画像的关键词列表 **不能超过为1000个字符**。须征得用户同意才可传入该参数</span></a>
<a class="sourceLine" id="cb12-6" title="6">        <span class="kw">private</span> <span class="bu">String</span> mData;<span class="co">// 可选参数，设置额外的用户信息 **不能超过为1000个字符**</span></a>
<a class="sourceLine" id="cb12-7" title="7">        <span class="kw">private</span> <span class="dt">int</span> mTitleBarTheme = TTAdConstant.<span class="fu">TITLE_BAR_THEME_LIGHT</span>;<span class="co">// 可选参数，设置落地页主题，默认为TTAdConstant#TITLE_BAR_THEME_LIGHT</span></a>
<a class="sourceLine" id="cb12-8" title="8">        <span class="kw">private</span> <span class="dt">boolean</span> mAllowShowNotify = <span class="kw">true</span>;<span class="co">// 可选参数，设置是否允许SDK弹出通知：true允许、false禁止。默认为true允许</span></a>
<a class="sourceLine" id="cb12-9" title="9">        <span class="kw">private</span> <span class="dt">boolean</span> mIsDebug = <span class="kw">false</span>;<span class="co">// 可选参数，是否打开debug调试信息输出：true打开、false关闭。默认false关闭</span></a>
<a class="sourceLine" id="cb12-10" title="10">        <span class="kw">private</span> <span class="dt">boolean</span> mAllowShowPageWhenScreenLock = <span class="kw">false</span>;<span class="co">// 可选参数，设置是否允许落地页出现在锁屏上面：true允许、false禁止。默认为false禁止</span></a>
<a class="sourceLine" id="cb12-11" title="11">        <span class="kw">private</span> <span class="dt">int</span>[] mDirectDownloadNetworkType;</a>
<a class="sourceLine" id="cb12-12" title="12">        <span class="kw">private</span> <span class="dt">boolean</span> mIsUseTextureView = <span class="kw">false</span>;<span class="co">// 可选参数，设置是否使用texture播放视频：true使用、false不使用。默认为false不使用（使用的是surface）</span></a>
<a class="sourceLine" id="cb12-13" title="13">        <span class="kw">private</span> <span class="dt">boolean</span> mIsSupportMultiProcess = <span class="kw">false</span>;<span class="co">// 可选参数，设置是否支持多进程：true支持、false不支持。默认为false不支持</span></a>
<a class="sourceLine" id="cb12-14" title="14">        <span class="kw">private</span> IHttpStack mHttpStack;<span class="co">//可选参数，设置外部网络请求，默认为urlconnection</span></a>
<a class="sourceLine" id="cb12-15" title="15">        <span class="kw">private</span> <span class="dt">boolean</span> mIsAsyncInit = <span class="kw">false</span>;<span class="co">//是否异步初始化sdk</span></a>
<a class="sourceLine" id="cb12-16" title="16">        <span class="kw">private</span> TTCustomController mCustomController;<span class="co">//可选参数，可以设置隐私信息控制开关</span></a>
<a class="sourceLine" id="cb12-17" title="17">    }</a></code></pre></div>
<h4 id="隐私信息控制开关">1.4.3 隐私信息控制开关</h4>
<div class="sourceCode" id="cb13"><pre class="sourceCode java"><code class="sourceCode java"><a class="sourceLine" id="cb13-1" title="1"><span class="kw">public</span> <span class="kw">abstract</span> <span class="kw">class</span> TTCustomController {</a>
<a class="sourceLine" id="cb13-2" title="2"></a>
<a class="sourceLine" id="cb13-3" title="3">    <span class="co">/**</span></a>
<a class="sourceLine" id="cb13-4" title="4">     <span class="co">*</span> 是否允许SDK主动使用地理位置信息</a>
<a class="sourceLine" id="cb13-5" title="5">     <span class="co">*</span></a>
<a class="sourceLine" id="cb13-6" title="6">     <span class="co">* </span><span class="an">@return </span>true可以获取，false禁止获取。默认为true</a>
<a class="sourceLine" id="cb13-7" title="7">     <span class="co">*/</span></a>
<a class="sourceLine" id="cb13-8" title="8">    <span class="kw">public</span> <span class="dt">boolean</span> <span class="fu">isCanUseLocation</span>() {</a>
<a class="sourceLine" id="cb13-9" title="9">        <span class="kw">return</span> <span class="kw">true</span>;</a>
<a class="sourceLine" id="cb13-10" title="10">    }</a>
<a class="sourceLine" id="cb13-11" title="11"></a>
<a class="sourceLine" id="cb13-12" title="12">    <span class="co">/**</span></a>
<a class="sourceLine" id="cb13-13" title="13">     <span class="co">*</span> 当isCanUseLocation<span class="co">=</span>false时，可传入地理位置信息，穿山甲sdk使用您传入的地理位置信息</a>
<a class="sourceLine" id="cb13-14" title="14">     <span class="co">*</span></a>
<a class="sourceLine" id="cb13-15" title="15">     <span class="co">* </span><span class="an">@return </span>地理位置参数</a>
<a class="sourceLine" id="cb13-16" title="16">     <span class="co">*/</span></a>
<a class="sourceLine" id="cb13-17" title="17">    <span class="kw">public</span> TTLocation <span class="fu">getTTLocation</span>() {</a>
<a class="sourceLine" id="cb13-18" title="18">        <span class="kw">return</span> <span class="kw">null</span>;</a>
<a class="sourceLine" id="cb13-19" title="19">    }</a>
<a class="sourceLine" id="cb13-20" title="20">    </a>
<a class="sourceLine" id="cb13-21" title="21">    <span class="co">/**</span></a>
<a class="sourceLine" id="cb13-22" title="22">     <span class="co">*</span> 是否允许SDK主动使用手机硬件参数，如：imei</a>
<a class="sourceLine" id="cb13-23" title="23">     <span class="co">*</span></a>
<a class="sourceLine" id="cb13-24" title="24">     <span class="co">* </span><span class="an">@return </span>true可以使用，false禁止使用。默认为true</a>
<a class="sourceLine" id="cb13-25" title="25">     <span class="co">*/</span></a>
<a class="sourceLine" id="cb13-26" title="26">    <span class="kw">public</span> <span class="dt">boolean</span> <span class="fu">isCanUsePhoneState</span>() {</a>
<a class="sourceLine" id="cb13-27" title="27">        <span class="kw">return</span> <span class="kw">true</span>;</a>
<a class="sourceLine" id="cb13-28" title="28">    }</a>
<a class="sourceLine" id="cb13-29" title="29"></a>
<a class="sourceLine" id="cb13-30" title="30">    <span class="co">/**</span></a>
<a class="sourceLine" id="cb13-31" title="31">     <span class="co">*</span> 当isCanUsePhoneState<span class="co">=</span>false时，可传入imei信息，穿山甲sdk使用您传入的imei信息</a>
<a class="sourceLine" id="cb13-32" title="32">     <span class="co">*</span></a>
<a class="sourceLine" id="cb13-33" title="33">     <span class="co">* </span><span class="an">@return </span>imei信息</a>
<a class="sourceLine" id="cb13-34" title="34">     <span class="co">*/</span></a>
<a class="sourceLine" id="cb13-35" title="35">    <span class="kw">public</span> <span class="bu">String</span> <span class="fu">getDevImei</span>() {</a>
<a class="sourceLine" id="cb13-36" title="36">        <span class="kw">return</span> <span class="kw">null</span>;</a>
<a class="sourceLine" id="cb13-37" title="37">    }</a>
<a class="sourceLine" id="cb13-38" title="38"></a>
<a class="sourceLine" id="cb13-39" title="39">    <span class="co">/**</span></a>
<a class="sourceLine" id="cb13-40" title="40">     <span class="co">*</span> 是否允许SDK主动使用ACCESS_WIFI_STATE权限</a>
<a class="sourceLine" id="cb13-41" title="41">     <span class="co">*</span></a>
<a class="sourceLine" id="cb13-42" title="42">     <span class="co">* </span><span class="an">@return </span>true可以使用，false禁止使用。默认为true</a>
<a class="sourceLine" id="cb13-43" title="43">     <span class="co">*/</span></a>
<a class="sourceLine" id="cb13-44" title="44">    <span class="kw">public</span> <span class="dt">boolean</span> <span class="fu">isCanUseWifiState</span>() {</a>
<a class="sourceLine" id="cb13-45" title="45">        <span class="kw">return</span> <span class="kw">true</span>;</a>
<a class="sourceLine" id="cb13-46" title="46">    }</a>
<a class="sourceLine" id="cb13-47" title="47"></a>
<a class="sourceLine" id="cb13-48" title="48">    <span class="co">/**</span></a>
<a class="sourceLine" id="cb13-49" title="49">     <span class="co">*</span> 是否允许SDK主动使用WRITE_EXTERNAL_STORAGE权限</a>
<a class="sourceLine" id="cb13-50" title="50">     <span class="co">*</span></a>
<a class="sourceLine" id="cb13-51" title="51">     <span class="co">* </span><span class="an">@return </span>true可以使用，false禁止使用。默认为true</a>
<a class="sourceLine" id="cb13-52" title="52">     <span class="co">*/</span></a>
<a class="sourceLine" id="cb13-53" title="53">    <span class="kw">public</span> <span class="dt">boolean</span> <span class="fu">isCanUseWriteExternal</span>() {</a>
<a class="sourceLine" id="cb13-54" title="54">        <span class="kw">return</span> <span class="kw">true</span>;</a>
<a class="sourceLine" id="cb13-55" title="55">    }</a>
<a class="sourceLine" id="cb13-56" title="56"></a>
<a class="sourceLine" id="cb13-57" title="57">}</a></code></pre></div>
<h2 id="加载广告">2.加载广告</h2>
<h3 id="构建ttadmanager对象">2.1 构建TTAdManager对象 :</h3>
<p>TTAdManager对象为整个SDK的入口接口，可用于广告获取、权限请求、版本号获取等。</p>
<p>构建方法：</p>
<div class="sourceCode" id="cb14"><pre class="sourceCode java"><code class="sourceCode java"><a class="sourceLine" id="cb14-1" title="1"><span class="co">//一定要在初始化后才能调用，否则为空</span></a>
<a class="sourceLine" id="cb14-2" title="2">TTAdManager ttAdManager = TTAdSdk.<span class="fu">getAdManager</span>();</a></code></pre></div>
<p>TTAdManger接口说明：</p>
<div class="sourceCode" id="cb15"><pre class="sourceCode java"><code class="sourceCode java"><a class="sourceLine" id="cb15-1" title="1"><span class="kw">public</span> <span class="kw">interface</span> TTAdManager {</a>
<a class="sourceLine" id="cb15-2" title="2"></a>
<a class="sourceLine" id="cb15-3" title="3">    TTAdNative <span class="fu">createAdNative</span>(<span class="bu">Context</span> context); <span class="co">// 创建TTAdNative对象 必须采用activity</span></a>
<a class="sourceLine" id="cb15-4" title="4"></a>
<a class="sourceLine" id="cb15-5" title="5">    <span class="co">//部分机型需要主动申请权限，如 READ_PHONE_STATE权限</span></a>
<a class="sourceLine" id="cb15-6" title="6">    <span class="dt">void</span> <span class="fu">requestPermissionIfNecessary</span>(<span class="bu">Context</span> context);</a>
<a class="sourceLine" id="cb15-7" title="7"></a>
<a class="sourceLine" id="cb15-8" title="8"></a>
<a class="sourceLine" id="cb15-9" title="9">    <span class="co">//退出时尝试显示&quot;提示安装app&quot;对话框，返回值：true显示对话框、false不显示对话框</span></a>
<a class="sourceLine" id="cb15-10" title="10">    <span class="dt">boolean</span> <span class="fu">tryShowInstallDialogWhenExit</span>(<span class="bu">Context</span> context, <span class="dt">final</span> ExitInstallListener listener);</a>
<a class="sourceLine" id="cb15-11" title="11"></a>
<a class="sourceLine" id="cb15-12" title="12">    <span class="co">/**</span></a>
<a class="sourceLine" id="cb15-13" title="13">     <span class="co">*</span> 获取穿山甲sdk版本号</a>
<a class="sourceLine" id="cb15-14" title="14">     <span class="co">*</span></a>
<a class="sourceLine" id="cb15-15" title="15">     <span class="co">* </span><span class="an">@return </span>版本号</a>
<a class="sourceLine" id="cb15-16" title="16">     <span class="co">*/</span></a>
<a class="sourceLine" id="cb15-17" title="17">    <span class="bu">String</span> <span class="fu">getSDKVersion</span>();</a>
<a class="sourceLine" id="cb15-18" title="18">}</a></code></pre></div>
<h3 id="构建ttadnative对象">2.2 构建TTAdNative对象</h3>
<p>TTAdNative为加载广告的接口，用于加载信息流广告、Banner广告、开屏广告、插屏广告等，并提供了加载回调监听器，建议是Activity的成员变量。</p>
<p>构建方法：</p>
<div class="sourceCode" id="cb16"><pre class="sourceCode java"><code class="sourceCode java"><a class="sourceLine" id="cb16-1" title="1">TTAdNative mTTAdNative = TTAdSdk.<span class="fu">getAdManager</span>().<span class="fu">createAdNative</span>(baseContext);<span class="co">//baseContext建议为activity</span></a></code></pre></div>
<p>TTAdNative接口说明：</p>
<div class="sourceCode" id="cb17"><pre class="sourceCode java"><code class="sourceCode java"><a class="sourceLine" id="cb17-1" title="1"><span class="kw">public</span> <span class="kw">interface</span> TTAdNative {</a>
<a class="sourceLine" id="cb17-2" title="2"></a>
<a class="sourceLine" id="cb17-3" title="3">    <span class="co">/**</span></a>
<a class="sourceLine" id="cb17-4" title="4">     <span class="co">* </span><span class="an">@param adSlot </span>请求配置信息</a>
<a class="sourceLine" id="cb17-5" title="5">     <span class="co">*</span> <span class="an">@param listener </span>加载结果回调</a>
<a class="sourceLine" id="cb17-6" title="6">     <span class="co">*</span> 异步加载Feed广告，结果会通过FeedAdListener回调</a>
<a class="sourceLine" id="cb17-7" title="7">     <span class="co">*/</span></a>
<a class="sourceLine" id="cb17-8" title="8">    <span class="dt">void</span> <span class="fu">loadFeedAd</span>(AdSlot adSlot, <span class="at">@NonNull</span> FeedAdListener listener);</a>
<a class="sourceLine" id="cb17-9" title="9"></a>
<a class="sourceLine" id="cb17-10" title="10">     <span class="co">/**</span></a>
<a class="sourceLine" id="cb17-11" title="11">     <span class="co">* </span><span class="an">@param adSlot </span>请求配置信息</a>
<a class="sourceLine" id="cb17-12" title="12">     <span class="co">*</span> <span class="an">@param listener </span>加载结果回调</a>
<a class="sourceLine" id="cb17-13" title="13">     <span class="co">*</span> 异步加载原生DrawFeed广告，结果会通过DrawFeedAdListener回调</a>
<a class="sourceLine" id="cb17-14" title="14">     <span class="co">*/</span></a>
<a class="sourceLine" id="cb17-15" title="15">    <span class="dt">void</span> <span class="fu">loadDrawFeedAd</span>(AdSlot adSlot, <span class="at">@NonNull</span> DrawFeedAdListener listener);</a>
<a class="sourceLine" id="cb17-16" title="16"></a>
<a class="sourceLine" id="cb17-17" title="17">    <span class="co">/**</span></a>
<a class="sourceLine" id="cb17-18" title="18">     <span class="co">* </span><span class="an">@param adSlot </span>请求配置信息</a>
<a class="sourceLine" id="cb17-19" title="19">     <span class="co">*</span> <span class="an">@param listener </span>加载结果回调</a>
<a class="sourceLine" id="cb17-20" title="20">     <span class="co">*</span> 异步加载Native广告，结果会通过NativeAdListener回调</a>
<a class="sourceLine" id="cb17-21" title="21">     <span class="co">*/</span></a>
<a class="sourceLine" id="cb17-22" title="22">    <span class="dt">void</span> <span class="fu">loadNativeAd</span>(AdSlot adSlot, <span class="at">@NonNull</span> NativeAdListener listener);</a>
<a class="sourceLine" id="cb17-23" title="23"></a>
<a class="sourceLine" id="cb17-24" title="24">    <span class="co">/**</span></a>
<a class="sourceLine" id="cb17-25" title="25">     <span class="co">* </span><span class="an">@param adSlot </span>请求配置信息</a>
<a class="sourceLine" id="cb17-26" title="26">     <span class="co">*</span> <span class="an">@param listener </span>加载结果回调</a>
<a class="sourceLine" id="cb17-27" title="27">     <span class="co">*</span> 异步加载Banner广告，结果会通过BannerAdListener回调</a>
<a class="sourceLine" id="cb17-28" title="28">     <span class="co">*/</span></a>
<a class="sourceLine" id="cb17-29" title="29">    <span class="dt">void</span> <span class="fu">loadBannerAd</span>(AdSlot adSlot, <span class="at">@NonNull</span> BannerAdListener listener);</a>
<a class="sourceLine" id="cb17-30" title="30"></a>
<a class="sourceLine" id="cb17-31" title="31">    <span class="co">/**</span></a>
<a class="sourceLine" id="cb17-32" title="32">     <span class="co">* </span><span class="an">@param adSlot </span>  请求配置信息</a>
<a class="sourceLine" id="cb17-33" title="33">     <span class="co">*</span> <span class="an">@param listener </span>加载结果回调</a>
<a class="sourceLine" id="cb17-34" title="34">     <span class="co">*</span> 异步加载InteractionAd广告，结果会通过InteractionAdListener回调</a>
<a class="sourceLine" id="cb17-35" title="35">     <span class="co">*/</span></a>
<a class="sourceLine" id="cb17-36" title="36">    <span class="dt">void</span> <span class="fu">loadInteractionAd</span>(AdSlot adSlot, <span class="at">@NonNull</span> InteractionAdListener listener);</a>
<a class="sourceLine" id="cb17-37" title="37"></a>
<a class="sourceLine" id="cb17-38" title="38">    <span class="co">/**</span></a>
<a class="sourceLine" id="cb17-39" title="39">     <span class="co">* </span><span class="an">@param adSlot </span>  请求配置信息</a>
<a class="sourceLine" id="cb17-40" title="40">     <span class="co">*</span> <span class="an">@param listener </span>加载结果回调</a>
<a class="sourceLine" id="cb17-41" title="41">     <span class="co">*</span> <span class="an">@param timeOut </span> 加载超时时间</a>
<a class="sourceLine" id="cb17-42" title="42">     <span class="co">*</span> 异步加载Splash广告，结果会通过SplashAdListener回调</a>
<a class="sourceLine" id="cb17-43" title="43">     <span class="co">*/</span></a>
<a class="sourceLine" id="cb17-44" title="44">    <span class="dt">void</span> <span class="fu">loadSplashAd</span>(AdSlot adSlot, <span class="at">@NonNull</span> SplashAdListener listener, <span class="dt">int</span> timeOut);</a>
<a class="sourceLine" id="cb17-45" title="45"></a>
<a class="sourceLine" id="cb17-46" title="46">    <span class="co">/**</span></a>
<a class="sourceLine" id="cb17-47" title="47">     <span class="co">* </span><span class="an">@param adSlot </span>  请求配置信息</a>
<a class="sourceLine" id="cb17-48" title="48">     <span class="co">*</span> <span class="an">@param listener </span>加载结果回调</a>
<a class="sourceLine" id="cb17-49" title="49">     <span class="co">*</span> 异步加载Splash广告，结果会通过SplashAdListener回调</a>
<a class="sourceLine" id="cb17-50" title="50">     <span class="co">*/</span></a>
<a class="sourceLine" id="cb17-51" title="51">    <span class="dt">void</span> <span class="fu">loadSplashAd</span>(AdSlot adSlot, <span class="at">@NonNull</span> SplashAdListener listener);</a>
<a class="sourceLine" id="cb17-52" title="52"></a>
<a class="sourceLine" id="cb17-53" title="53">    <span class="co">/**</span></a>
<a class="sourceLine" id="cb17-54" title="54">     <span class="co">*</span> 异步加载激励视频广告，结果会通过RewardVideoAdListener回调</a>
<a class="sourceLine" id="cb17-55" title="55">     <span class="co">* </span><span class="an">@param adSlot</span></a>
<a class="sourceLine" id="cb17-56" title="56">     <span class="co">*</span> <span class="an">@param listener</span></a>
<a class="sourceLine" id="cb17-57" title="57">     <span class="co">*/</span></a>
<a class="sourceLine" id="cb17-58" title="58">    <span class="dt">void</span> <span class="fu">loadRewardVideoAd</span>(AdSlot adSlot, <span class="at">@NonNull</span> RewardVideoAdListener listener);</a>
<a class="sourceLine" id="cb17-59" title="59"></a>
<a class="sourceLine" id="cb17-60" title="60">    <span class="co">/**</span></a>
<a class="sourceLine" id="cb17-61" title="61">     <span class="co">*</span> 异步加载全屏视频广告，结果会通过FullScreenVideoAdListener回调</a>
<a class="sourceLine" id="cb17-62" title="62">     <span class="co">* </span><span class="an">@param adSlot</span></a>
<a class="sourceLine" id="cb17-63" title="63">     <span class="co">*</span> <span class="an">@param listener</span></a>
<a class="sourceLine" id="cb17-64" title="64">     <span class="co">*/</span></a>
<a class="sourceLine" id="cb17-65" title="65">    <span class="dt">void</span> <span class="fu">loadFullScreenVideoAd</span>(AdSlot adSlot, <span class="at">@NonNull</span> FullScreenVideoAdListener listener);</a>
<a class="sourceLine" id="cb17-66" title="66"></a>
<a class="sourceLine" id="cb17-67" title="67">    <span class="co">/**</span></a>
<a class="sourceLine" id="cb17-68" title="68">     <span class="co">* </span><span class="an">@param adSlot </span>请求配置信息</a>
<a class="sourceLine" id="cb17-69" title="69">     <span class="co">*</span> <span class="an">@param listener </span>加载结果回调</a>
<a class="sourceLine" id="cb17-70" title="70">     <span class="co">*</span> 异步加载个性化模板信息流广告，结果会通过NativeExpressAdListener回调</a>
<a class="sourceLine" id="cb17-71" title="71">     <span class="co">*/</span></a>
<a class="sourceLine" id="cb17-72" title="72">    <span class="dt">void</span> <span class="fu">loadNativeExpressAd</span>(AdSlot adSlot, <span class="at">@NonNull</span> NativeExpressAdListener listener);</a>
<a class="sourceLine" id="cb17-73" title="73">    </a>
<a class="sourceLine" id="cb17-74" title="74">    <span class="co">/**</span></a>
<a class="sourceLine" id="cb17-75" title="75">     <span class="co">* </span><span class="an">@param adSlot </span>请求配置信息</a>
<a class="sourceLine" id="cb17-76" title="76">     <span class="co">*</span> <span class="an">@param listener </span>加载结果回调</a>
<a class="sourceLine" id="cb17-77" title="77">     <span class="co">*</span> 异步加载个性化模板draw视频广告，结果会通过NativeExpressAdListener回调</a>
<a class="sourceLine" id="cb17-78" title="78">     <span class="co">*/</span></a>
<a class="sourceLine" id="cb17-79" title="79">    <span class="dt">void</span> <span class="fu">loadExpressDrawFeedAd</span>(AdSlot adSlot, <span class="at">@NonNull</span> NativeExpressAdListener listener);</a>
<a class="sourceLine" id="cb17-80" title="80">    </a>
<a class="sourceLine" id="cb17-81" title="81">    <span class="co">/**</span></a>
<a class="sourceLine" id="cb17-82" title="82">     <span class="co">* </span><span class="an">@param adSlot </span>请求配置信息</a>
<a class="sourceLine" id="cb17-83" title="83">     <span class="co">*</span> <span class="an">@param listener </span>加载结果回调</a>
<a class="sourceLine" id="cb17-84" title="84">     <span class="co">*</span> 异步加载个性化模板Banner广告，结果会通过NativeExpressAdListener回调</a>
<a class="sourceLine" id="cb17-85" title="85">     <span class="co">*/</span></a>
<a class="sourceLine" id="cb17-86" title="86">     <span class="dt">void</span> <span class="fu">loadBannerExpressAd</span>(AdSlot adSlot, <span class="at">@NonNull</span> NativeExpressAdListener listener);</a>
<a class="sourceLine" id="cb17-87" title="87">    </a>
<a class="sourceLine" id="cb17-88" title="88">    <span class="co">/**</span></a>
<a class="sourceLine" id="cb17-89" title="89">     <span class="co">* </span><span class="an">@param adSlot </span>请求配置信息</a>
<a class="sourceLine" id="cb17-90" title="90">     <span class="co">*</span> <span class="an">@param listener </span>加载结果回调</a>
<a class="sourceLine" id="cb17-91" title="91">     <span class="co">*</span> 异步加载个性化模板插屏广告，结果会通过NativeExpressAdListener回调</a>
<a class="sourceLine" id="cb17-92" title="92">     <span class="co">*/</span></a>
<a class="sourceLine" id="cb17-93" title="93">     <span class="dt">void</span> <span class="fu">loadInteractionExpressAd</span>(AdSlot adSlot, <span class="at">@NonNull</span> NativeExpressAdListener listener);</a>
<a class="sourceLine" id="cb17-94" title="94"></a>
<a class="sourceLine" id="cb17-95" title="95">    <span class="co">/**</span></a>
<a class="sourceLine" id="cb17-96" title="96">     <span class="co">*</span> 信息流广告加载监听器</a>
<a class="sourceLine" id="cb17-97" title="97">     <span class="co">*/</span></a>
<a class="sourceLine" id="cb17-98" title="98">    <span class="kw">interface</span> FeedAdListener {</a>
<a class="sourceLine" id="cb17-99" title="99"></a>
<a class="sourceLine" id="cb17-100" title="100">        <span class="co">/**</span></a>
<a class="sourceLine" id="cb17-101" title="101">         <span class="co">*</span> 加载失败的回调</a>
<a class="sourceLine" id="cb17-102" title="102">         <span class="co">*</span></a>
<a class="sourceLine" id="cb17-103" title="103">         <span class="co">* </span><span class="an">@param code</span></a>
<a class="sourceLine" id="cb17-104" title="104">         <span class="co">*</span> <span class="an">@param message</span></a>
<a class="sourceLine" id="cb17-105" title="105">         <span class="co">*/</span></a>
<a class="sourceLine" id="cb17-106" title="106">        <span class="at">@MainThread</span></a>
<a class="sourceLine" id="cb17-107" title="107">        <span class="dt">void</span> <span class="fu">onError</span>(<span class="dt">int</span> code, <span class="bu">String</span> message);</a>
<a class="sourceLine" id="cb17-108" title="108"></a>
<a class="sourceLine" id="cb17-109" title="109">        <span class="co">/**</span></a>
<a class="sourceLine" id="cb17-110" title="110">         <span class="co">*</span> 广告加载成功的回调，接入方可以在这个回调中进行渲染</a>
<a class="sourceLine" id="cb17-111" title="111">         <span class="co">*</span></a>
<a class="sourceLine" id="cb17-112" title="112">         <span class="co">* </span><span class="an">@param ads </span>返回的广告列表</a>
<a class="sourceLine" id="cb17-113" title="113">         <span class="co">*/</span></a>
<a class="sourceLine" id="cb17-114" title="114">        <span class="at">@MainThread</span></a>
<a class="sourceLine" id="cb17-115" title="115">        <span class="dt">void</span> <span class="fu">onFeedAdLoad</span>(<span class="bu">List</span>&lt;TTFeedAd&gt; ads);</a>
<a class="sourceLine" id="cb17-116" title="116"></a>
<a class="sourceLine" id="cb17-117" title="117">    }</a>
<a class="sourceLine" id="cb17-118" title="118"></a>
<a class="sourceLine" id="cb17-119" title="119">    <span class="co">/**</span></a>
<a class="sourceLine" id="cb17-120" title="120">     <span class="co">*</span> 原生广告加载监听器</a>
<a class="sourceLine" id="cb17-121" title="121">     <span class="co">*/</span></a>
<a class="sourceLine" id="cb17-122" title="122">    <span class="kw">interface</span> NativeAdListener {</a>
<a class="sourceLine" id="cb17-123" title="123"></a>
<a class="sourceLine" id="cb17-124" title="124">        <span class="co">/**</span></a>
<a class="sourceLine" id="cb17-125" title="125">         <span class="co">*</span> 加载失败的回调</a>
<a class="sourceLine" id="cb17-126" title="126">         <span class="co">*</span></a>
<a class="sourceLine" id="cb17-127" title="127">         <span class="co">* </span><span class="an">@param code</span></a>
<a class="sourceLine" id="cb17-128" title="128">         <span class="co">*</span> <span class="an">@param message</span></a>
<a class="sourceLine" id="cb17-129" title="129">         <span class="co">*/</span></a>
<a class="sourceLine" id="cb17-130" title="130">        <span class="at">@MainThread</span></a>
<a class="sourceLine" id="cb17-131" title="131">        <span class="dt">void</span> <span class="fu">onError</span>(<span class="dt">int</span> code, <span class="bu">String</span> message);</a>
<a class="sourceLine" id="cb17-132" title="132"></a>
<a class="sourceLine" id="cb17-133" title="133">        <span class="co">/**</span></a>
<a class="sourceLine" id="cb17-134" title="134">         <span class="co">*</span> 广告加载成功的回调，接入方可以在这个回调中进行渲染</a>
<a class="sourceLine" id="cb17-135" title="135">         <span class="co">*</span></a>
<a class="sourceLine" id="cb17-136" title="136">         <span class="co">* </span><span class="an">@param ads </span>返回的广告列表</a>
<a class="sourceLine" id="cb17-137" title="137">         <span class="co">*/</span></a>
<a class="sourceLine" id="cb17-138" title="138">        <span class="at">@MainThread</span></a>
<a class="sourceLine" id="cb17-139" title="139">        <span class="dt">void</span> <span class="fu">onNativeAdLoad</span>(<span class="bu">List</span>&lt;TTNativeAd&gt; ads);</a>
<a class="sourceLine" id="cb17-140" title="140"></a>
<a class="sourceLine" id="cb17-141" title="141">    }</a>
<a class="sourceLine" id="cb17-142" title="142"></a>
<a class="sourceLine" id="cb17-143" title="143">    <span class="co">/**</span></a>
<a class="sourceLine" id="cb17-144" title="144">     <span class="co">*</span> Banner广告加载监听器</a>
<a class="sourceLine" id="cb17-145" title="145">     <span class="co">*/</span></a>
<a class="sourceLine" id="cb17-146" title="146">    <span class="kw">interface</span> BannerAdListener {</a>
<a class="sourceLine" id="cb17-147" title="147"></a>
<a class="sourceLine" id="cb17-148" title="148">        <span class="co">/**</span></a>
<a class="sourceLine" id="cb17-149" title="149">         <span class="co">*</span> 加载失败的回调</a>
<a class="sourceLine" id="cb17-150" title="150">         <span class="co">*</span></a>
<a class="sourceLine" id="cb17-151" title="151">         <span class="co">* </span><span class="an">@param code</span></a>
<a class="sourceLine" id="cb17-152" title="152">         <span class="co">*</span> <span class="an">@param message</span></a>
<a class="sourceLine" id="cb17-153" title="153">         <span class="co">*/</span></a>
<a class="sourceLine" id="cb17-154" title="154">        <span class="at">@MainThread</span></a>
<a class="sourceLine" id="cb17-155" title="155">        <span class="dt">void</span> <span class="fu">onError</span>(<span class="dt">int</span> code, <span class="bu">String</span> message);</a>
<a class="sourceLine" id="cb17-156" title="156"></a>
<a class="sourceLine" id="cb17-157" title="157">        <span class="co">/**</span></a>
<a class="sourceLine" id="cb17-158" title="158">         <span class="co">*</span> 广告加载完成的回调，接入方可以在这个回调中进行渲染</a>
<a class="sourceLine" id="cb17-159" title="159">         <span class="co">*</span></a>
<a class="sourceLine" id="cb17-160" title="160">         <span class="co">* </span><span class="an">@param ad</span></a>
<a class="sourceLine" id="cb17-161" title="161">         <span class="co">*/</span></a>
<a class="sourceLine" id="cb17-162" title="162">        <span class="at">@MainThread</span></a>
<a class="sourceLine" id="cb17-163" title="163">        <span class="dt">void</span> <span class="fu">onBannerAdLoad</span>(TTBannerAd ad);</a>
<a class="sourceLine" id="cb17-164" title="164"></a>
<a class="sourceLine" id="cb17-165" title="165">    }</a>
<a class="sourceLine" id="cb17-166" title="166"></a>
<a class="sourceLine" id="cb17-167" title="167">    <span class="co">/**</span></a>
<a class="sourceLine" id="cb17-168" title="168">     <span class="co">*</span> 插屏广告加载监听器</a>
<a class="sourceLine" id="cb17-169" title="169">     <span class="co">*/</span></a>
<a class="sourceLine" id="cb17-170" title="170">    <span class="kw">interface</span> InteractionAdListener {</a>
<a class="sourceLine" id="cb17-171" title="171">        <span class="co">/**</span></a>
<a class="sourceLine" id="cb17-172" title="172">         <span class="co">*</span> 加载失败回调</a>
<a class="sourceLine" id="cb17-173" title="173">         <span class="co">* </span><span class="an">@param code</span></a>
<a class="sourceLine" id="cb17-174" title="174">         <span class="co">*</span> <span class="an">@param message</span></a>
<a class="sourceLine" id="cb17-175" title="175">         <span class="co">*/</span></a>
<a class="sourceLine" id="cb17-176" title="176">        <span class="at">@MainThread</span></a>
<a class="sourceLine" id="cb17-177" title="177">        <span class="dt">void</span> <span class="fu">onError</span>(<span class="dt">int</span> code,<span class="bu">String</span> message);</a>
<a class="sourceLine" id="cb17-178" title="178"></a>
<a class="sourceLine" id="cb17-179" title="179">        <span class="co">/**</span></a>
<a class="sourceLine" id="cb17-180" title="180">         <span class="co">*</span> 广告加载成功回调</a>
<a class="sourceLine" id="cb17-181" title="181">         <span class="co">*</span></a>
<a class="sourceLine" id="cb17-182" title="182">         <span class="co">*/</span></a>
<a class="sourceLine" id="cb17-183" title="183">        <span class="at">@MainThread</span></a>
<a class="sourceLine" id="cb17-184" title="184">        <span class="dt">void</span> <span class="fu">onInteractionAdLoad</span>(TTInteractionAd ad);</a>
<a class="sourceLine" id="cb17-185" title="185">    }</a>
<a class="sourceLine" id="cb17-186" title="186"></a>
<a class="sourceLine" id="cb17-187" title="187">    <span class="co">/**</span></a>
<a class="sourceLine" id="cb17-188" title="188">     <span class="co">*</span> 开屏广告加载监听器</a>
<a class="sourceLine" id="cb17-189" title="189">     <span class="co">*/</span></a>
<a class="sourceLine" id="cb17-190" title="190">    <span class="kw">interface</span> SplashAdListener {</a>
<a class="sourceLine" id="cb17-191" title="191">        <span class="co">/**</span></a>
<a class="sourceLine" id="cb17-192" title="192">         <span class="co">*</span> 加载失败回调</a>
<a class="sourceLine" id="cb17-193" title="193">         <span class="co">*</span></a>
<a class="sourceLine" id="cb17-194" title="194">         <span class="co">* </span><span class="an">@param code</span></a>
<a class="sourceLine" id="cb17-195" title="195">         <span class="co">*</span> <span class="an">@param message</span></a>
<a class="sourceLine" id="cb17-196" title="196">         <span class="co">*/</span></a>
<a class="sourceLine" id="cb17-197" title="197">        <span class="at">@MainThread</span></a>
<a class="sourceLine" id="cb17-198" title="198">        <span class="dt">void</span> <span class="fu">onError</span>(<span class="dt">int</span> code, <span class="bu">String</span> message);</a>
<a class="sourceLine" id="cb17-199" title="199"></a>
<a class="sourceLine" id="cb17-200" title="200">        <span class="co">/**</span></a>
<a class="sourceLine" id="cb17-201" title="201">         <span class="co">*</span> 开屏广告加载超时回调</a>
<a class="sourceLine" id="cb17-202" title="202">         <span class="co">*/</span></a>
<a class="sourceLine" id="cb17-203" title="203">        <span class="dt">void</span> <span class="fu">onTimeout</span>();</a>
<a class="sourceLine" id="cb17-204" title="204"></a>
<a class="sourceLine" id="cb17-205" title="205">        <span class="co">/**</span></a>
<a class="sourceLine" id="cb17-206" title="206">         <span class="co">*</span> 广告加载完成的回调，接入方可以在这个回调中进行渲染</a>
<a class="sourceLine" id="cb17-207" title="207">         <span class="co">*</span></a>
<a class="sourceLine" id="cb17-208" title="208">         <span class="co">* </span><span class="an">@param ad </span>开屏广告接口</a>
<a class="sourceLine" id="cb17-209" title="209">         <span class="co">*/</span></a>
<a class="sourceLine" id="cb17-210" title="210">        <span class="at">@MainThread</span></a>
<a class="sourceLine" id="cb17-211" title="211">        <span class="dt">void</span> <span class="fu">onSplashAdLoad</span>(TTSplashAd ad);</a>
<a class="sourceLine" id="cb17-212" title="212">    }</a>
<a class="sourceLine" id="cb17-213" title="213"></a>
<a class="sourceLine" id="cb17-214" title="214">    <span class="co">/**</span></a>
<a class="sourceLine" id="cb17-215" title="215">     <span class="co">*</span> 激励视频广告加载监听器</a>
<a class="sourceLine" id="cb17-216" title="216">     <span class="co">*/</span></a>
<a class="sourceLine" id="cb17-217" title="217">    <span class="kw">interface</span> RewardVideoAdListener {</a>
<a class="sourceLine" id="cb17-218" title="218">        <span class="co">/**</span></a>
<a class="sourceLine" id="cb17-219" title="219">         <span class="co">*</span> 加载失败回调</a>
<a class="sourceLine" id="cb17-220" title="220">         <span class="co">*</span></a>
<a class="sourceLine" id="cb17-221" title="221">         <span class="co">* </span><span class="an">@param code</span></a>
<a class="sourceLine" id="cb17-222" title="222">         <span class="co">*</span> <span class="an">@param message</span></a>
<a class="sourceLine" id="cb17-223" title="223">         <span class="co">*/</span></a>
<a class="sourceLine" id="cb17-224" title="224">        <span class="at">@MainThread</span></a>
<a class="sourceLine" id="cb17-225" title="225">        <span class="dt">void</span> <span class="fu">onError</span>(<span class="dt">int</span> code, <span class="bu">String</span> message);</a>
<a class="sourceLine" id="cb17-226" title="226"></a>
<a class="sourceLine" id="cb17-227" title="227">        <span class="co">/**</span></a>
<a class="sourceLine" id="cb17-228" title="228">         <span class="co">*</span> 广告加载完成的回调，接入方可以在这个回调中进行渲染</a>
<a class="sourceLine" id="cb17-229" title="229">         <span class="co">*</span></a>
<a class="sourceLine" id="cb17-230" title="230">         <span class="co">* </span><span class="an">@param ad </span>激励视频广告接口</a>
<a class="sourceLine" id="cb17-231" title="231">         <span class="co">*/</span></a>
<a class="sourceLine" id="cb17-232" title="232">        <span class="at">@MainThread</span></a>
<a class="sourceLine" id="cb17-233" title="233">        <span class="dt">void</span> <span class="fu">onRewardVideoAdLoad</span>(TTRewardVideoAd ad);</a>
<a class="sourceLine" id="cb17-234" title="234"></a>
<a class="sourceLine" id="cb17-235" title="235">        <span class="co">/**</span></a>
<a class="sourceLine" id="cb17-236" title="236">         <span class="co">*</span> 广告视频本地加载完成的回调，接入方可以在这个回调后直接播放本地视频</a>
<a class="sourceLine" id="cb17-237" title="237">         <span class="co">*/</span></a>
<a class="sourceLine" id="cb17-238" title="238">        <span class="dt">void</span> <span class="fu">onRewardVideoCached</span>();</a>
<a class="sourceLine" id="cb17-239" title="239">    }</a>
<a class="sourceLine" id="cb17-240" title="240"></a>
<a class="sourceLine" id="cb17-241" title="241">    <span class="co">/**</span></a>
<a class="sourceLine" id="cb17-242" title="242">     <span class="co">*</span> 全屏视频广告加载监听器</a>
<a class="sourceLine" id="cb17-243" title="243">     <span class="co">*/</span></a>
<a class="sourceLine" id="cb17-244" title="244">    <span class="kw">interface</span> FullScreenVideoAdListener {</a>
<a class="sourceLine" id="cb17-245" title="245">        <span class="co">/**</span></a>
<a class="sourceLine" id="cb17-246" title="246">         <span class="co">*</span> 加载失败回调</a>
<a class="sourceLine" id="cb17-247" title="247">         <span class="co">*</span></a>
<a class="sourceLine" id="cb17-248" title="248">         <span class="co">* </span><span class="an">@param code</span></a>
<a class="sourceLine" id="cb17-249" title="249">         <span class="co">*</span> <span class="an">@param message</span></a>
<a class="sourceLine" id="cb17-250" title="250">         <span class="co">*/</span></a>
<a class="sourceLine" id="cb17-251" title="251">        <span class="at">@MainThread</span></a>
<a class="sourceLine" id="cb17-252" title="252">        <span class="dt">void</span> <span class="fu">onError</span>(<span class="dt">int</span> code, <span class="bu">String</span> message);</a>
<a class="sourceLine" id="cb17-253" title="253"></a>
<a class="sourceLine" id="cb17-254" title="254">        <span class="co">/**</span></a>
<a class="sourceLine" id="cb17-255" title="255">         <span class="co">*</span> 广告加载完成的回调，接入方可以在这个回调中进行渲染</a>
<a class="sourceLine" id="cb17-256" title="256">         <span class="co">*</span></a>
<a class="sourceLine" id="cb17-257" title="257">         <span class="co">* </span><span class="an">@param ad </span>全屏视频广告接口</a>
<a class="sourceLine" id="cb17-258" title="258">         <span class="co">*/</span></a>
<a class="sourceLine" id="cb17-259" title="259">        <span class="at">@MainThread</span></a>
<a class="sourceLine" id="cb17-260" title="260">        <span class="dt">void</span> <span class="fu">onFullScreenVideoAdLoad</span>(TTFullScreenVideoAd ad);</a>
<a class="sourceLine" id="cb17-261" title="261"></a>
<a class="sourceLine" id="cb17-262" title="262">        <span class="co">/**</span></a>
<a class="sourceLine" id="cb17-263" title="263">         <span class="co">*</span> 广告视频本地加载完成的回调，接入方可以在这个回调后直接播放本地视频</a>
<a class="sourceLine" id="cb17-264" title="264">         <span class="co">*/</span></a>
<a class="sourceLine" id="cb17-265" title="265">        <span class="dt">void</span> <span class="fu">onFullScreenVideoCached</span>();</a>
<a class="sourceLine" id="cb17-266" title="266">    }</a>
<a class="sourceLine" id="cb17-267" title="267"></a>
<a class="sourceLine" id="cb17-268" title="268">    <span class="co">/**</span></a>
<a class="sourceLine" id="cb17-269" title="269">     <span class="co">*</span> 个性化模板广告加载监听器</a>
<a class="sourceLine" id="cb17-270" title="270">     <span class="co">*/</span></a>
<a class="sourceLine" id="cb17-271" title="271">     <span class="kw">interface</span> NativeExpressAdListener {</a>
<a class="sourceLine" id="cb17-272" title="272"></a>
<a class="sourceLine" id="cb17-273" title="273">         <span class="co">/**</span></a>
<a class="sourceLine" id="cb17-274" title="274">          <span class="co">*</span> 加载失败的回调</a>
<a class="sourceLine" id="cb17-275" title="275">          <span class="co">*</span></a>
<a class="sourceLine" id="cb17-276" title="276">          <span class="co">* </span><span class="an">@param code</span></a>
<a class="sourceLine" id="cb17-277" title="277">          <span class="co">*</span> <span class="an">@param message</span></a>
<a class="sourceLine" id="cb17-278" title="278">          <span class="co">*/</span></a>
<a class="sourceLine" id="cb17-279" title="279">         <span class="at">@MainThread</span></a>
<a class="sourceLine" id="cb17-280" title="280">         <span class="dt">void</span> <span class="fu">onError</span>(<span class="dt">int</span> code, <span class="bu">String</span> message);</a>
<a class="sourceLine" id="cb17-281" title="281"></a>
<a class="sourceLine" id="cb17-282" title="282">         <span class="co">/**</span></a>
<a class="sourceLine" id="cb17-283" title="283">          <span class="co">*</span> 广告加载成功的回调，接入方可以在这个回调中进行渲染</a>
<a class="sourceLine" id="cb17-284" title="284">          <span class="co">*</span></a>
<a class="sourceLine" id="cb17-285" title="285">          <span class="co">* </span><span class="an">@param ads </span>返回的广告列表</a>
<a class="sourceLine" id="cb17-286" title="286">          <span class="co">*/</span></a>
<a class="sourceLine" id="cb17-287" title="287">         <span class="at">@MainThread</span></a>
<a class="sourceLine" id="cb17-288" title="288">         <span class="dt">void</span> <span class="fu">onNativeExpressAdLoad</span>(<span class="bu">List</span>&lt;TTNativeExpressAd&gt; ads);</a>
<a class="sourceLine" id="cb17-289" title="289"></a>
<a class="sourceLine" id="cb17-290" title="290">     }</a>
<a class="sourceLine" id="cb17-291" title="291">}</a></code></pre></div>
<h3 id="构建adslot对象">2.3 构建AdSlot对象</h3>
<p>AdSlot对象为加载广告时需要设置的广告信息，在TTAdNative加载广告时使用。</p>
<p>构建方法：</p>
<div class="sourceCode" id="cb18"><pre class="sourceCode java"><code class="sourceCode java"><a class="sourceLine" id="cb18-1" title="1">AdSlot adSlot = <span class="kw">new</span> AdSlot.<span class="fu">Builder</span>()</a>
<a class="sourceLine" id="cb18-2" title="2">    <span class="co">// 必选参数 设置您的CodeId</span></a>
<a class="sourceLine" id="cb18-3" title="3">    .<span class="fu">setCodeId</span>(“<span class="dv">900486272</span><span class="st">&quot;)</span></a>
<a class="sourceLine" id="cb18-4" title="4">    <span class="co">// 必选参数 设置广告图片的最大尺寸及期望的图片宽高比，单位Px</span></a>
<a class="sourceLine" id="cb18-5" title="5">    <span class="co">// 注：必填字段，期望的图片尺寸，返回尺寸可能有差异</span></a>
<a class="sourceLine" id="cb18-6" title="6">    .<span class="fu">setImageAcceptedSize</span>(<span class="dv">640</span>, <span class="dv">320</span>)</a>
<a class="sourceLine" id="cb18-7" title="7">    <span class="co">//模板广告需要设置期望个性化模板广告的大小,单位dp,代码位是否属于个性化模板广告，请在穿山甲平台查看</span></a>
<a class="sourceLine" id="cb18-8" title="8">    .<span class="fu">setExpressViewAcceptedSize</span>(expressViewWidth, expressViewHeight)</a>
<a class="sourceLine" id="cb18-9" title="9">    <span class="co">// 可选参数 设置是否支持deeplink</span></a>
<a class="sourceLine" id="cb18-10" title="10">    .<span class="fu">setSupportDeepLink</span>(<span class="kw">true</span>)</a>
<a class="sourceLine" id="cb18-11" title="11">    <span class="co">// 可选参数，针对信息流广告设置每次请求的广告返回个数，最多支持3个</span></a>
<a class="sourceLine" id="cb18-12" title="12">    .<span class="fu">setAdCount</span>(<span class="dv">2</span>)</a>
<a class="sourceLine" id="cb18-13" title="13">    <span class="co">//请求原生广告时候需要设置，参数为TYPE_BANNER或TYPE_INTERACTION_AD</span></a>
<a class="sourceLine" id="cb18-14" title="14">    .<span class="fu">setNativeAdType</span>(AdSlot.<span class="fu">TYPE_BANNER</span>)</a>
<a class="sourceLine" id="cb18-15" title="15">    <span class="co">//激励视频奖励的名称，针对激励视频参数</span></a>
<a class="sourceLine" id="cb18-16" title="16">    .<span class="fu">setRewardName</span>(<span class="st">&quot;金币&quot;</span>)</a>
<a class="sourceLine" id="cb18-17" title="17">    <span class="co">//激励视频奖励个数</span></a>
<a class="sourceLine" id="cb18-18" title="18">    .<span class="fu">setRewardAmount</span>(<span class="dv">3</span>)</a>
<a class="sourceLine" id="cb18-19" title="19">    <span class="co">//用户ID,使用激励视频必传参数</span></a>
<a class="sourceLine" id="cb18-20" title="20">    <span class="co">//表来标识应用侧唯一用户；若非服务器回调模式或不需sdk透传，可设置为空字符串</span></a>
<a class="sourceLine" id="cb18-21" title="21">    .<span class="fu">setUserID</span>(<span class="st">&quot;user123&quot;</span>)</a>
<a class="sourceLine" id="cb18-22" title="22">    <span class="co">//设置期望视频播放的方向，为TTAdConstant.HORIZONTAL或TTAdConstant.VERTICAL</span></a>
<a class="sourceLine" id="cb18-23" title="23">    .<span class="fu">setOrientation</span>(orientation)</a>
<a class="sourceLine" id="cb18-24" title="24">    <span class="co">//激励视频奖励透传参数，字符串，如果用json对象，必须使用序列化为String类型,可为空</span></a>
<a class="sourceLine" id="cb18-25" title="25">    .<span class="fu">setMediaExtra</span>(<span class="st">&quot;media_extra&quot;</span>)</a>
<a class="sourceLine" id="cb18-26" title="26">    .<span class="fu">build</span>();</a></code></pre></div>
<h3 id="接入原生信息流广告ttfeedad">2.4 接入原生信息流广告（TTFeedAd）</h3>
<p>SDK为接入方提供了可自定义布局的信息流广告，包含大图、小图、组图和视频四种基本样式类型（具体的布局摆放可自行定义），及电话拨打、应用下载、跳转到落地页、跳转到浏览器四种交互类型。目前穿山甲信息流广告大图的尺寸为（16：9）、小图尺寸为（3：2）、组图3张为（3：2）、视频为（16:9）,标题和描述长度为6-26个字符。</p>
<h4 id="ttfeedad接口说明">2.4.1 TTFeedAd接口说明</h4>
<div class="sourceCode" id="cb19"><pre class="sourceCode java"><code class="sourceCode java"><a class="sourceLine" id="cb19-1" title="1"><span class="kw">public</span> <span class="kw">interface</span> TTFeedAd {</a>
<a class="sourceLine" id="cb19-2" title="2"></a>
<a class="sourceLine" id="cb19-3" title="3">    <span class="co">/**</span></a>
<a class="sourceLine" id="cb19-4" title="4">     <span class="co">*</span> 获取穿山甲穿山甲logo，图片大小：8<span class="co">0*80</span></a>
<a class="sourceLine" id="cb19-5" title="5">     <span class="co">*</span></a>
<a class="sourceLine" id="cb19-6" title="6">     <span class="co">* </span><span class="an">@return </span>bitmap对象</a>
<a class="sourceLine" id="cb19-7" title="7">     <span class="co">*/</span></a>
<a class="sourceLine" id="cb19-8" title="8">    Bitmap <span class="fu">getAdLogo</span>();</a>
<a class="sourceLine" id="cb19-9" title="9"></a>
<a class="sourceLine" id="cb19-10" title="10">    <span class="co">/**</span></a>
<a class="sourceLine" id="cb19-11" title="11">     <span class="co">*</span> 广告标题</a>
<a class="sourceLine" id="cb19-12" title="12">     <span class="co">*</span></a>
<a class="sourceLine" id="cb19-13" title="13">     <span class="co">* @</span>return</a>
<a class="sourceLine" id="cb19-14" title="14">     <span class="co">*/</span></a>
<a class="sourceLine" id="cb19-15" title="15">    <span class="bu">String</span> <span class="fu">getTitle</span>();</a>
<a class="sourceLine" id="cb19-16" title="16"></a>
<a class="sourceLine" id="cb19-17" title="17">    <span class="co">/**</span></a>
<a class="sourceLine" id="cb19-18" title="18">     <span class="co">*</span> 广告描述</a>
<a class="sourceLine" id="cb19-19" title="19">     <span class="co">*</span></a>
<a class="sourceLine" id="cb19-20" title="20">     <span class="co">* @</span>return</a>
<a class="sourceLine" id="cb19-21" title="21">     <span class="co">*/</span></a>
<a class="sourceLine" id="cb19-22" title="22">    <span class="bu">String</span> <span class="fu">getDescription</span>();</a>
<a class="sourceLine" id="cb19-23" title="23"></a>
<a class="sourceLine" id="cb19-24" title="24">    <span class="co">/**</span></a>
<a class="sourceLine" id="cb19-25" title="25">     <span class="co">*</span> 广告来源</a>
<a class="sourceLine" id="cb19-26" title="26">     <span class="co">*</span></a>
<a class="sourceLine" id="cb19-27" title="27">     <span class="co">* @</span>return</a>
<a class="sourceLine" id="cb19-28" title="28">     <span class="co">*/</span></a>
<a class="sourceLine" id="cb19-29" title="29">    <span class="bu">String</span> <span class="fu">getSource</span>();</a>
<a class="sourceLine" id="cb19-30" title="30"></a>
<a class="sourceLine" id="cb19-31" title="31">    <span class="co">/**</span></a>
<a class="sourceLine" id="cb19-32" title="32">     <span class="co">*</span> 广告图标Image</a>
<a class="sourceLine" id="cb19-33" title="33">     <span class="co">*</span></a>
<a class="sourceLine" id="cb19-34" title="34">     <span class="co">* @</span>return</a>
<a class="sourceLine" id="cb19-35" title="35">     <span class="co">*/</span></a>
<a class="sourceLine" id="cb19-36" title="36">    TTImage <span class="fu">getIcon</span>();</a>
<a class="sourceLine" id="cb19-37" title="37"></a>
<a class="sourceLine" id="cb19-38" title="38">    <span class="co">/**</span></a>
<a class="sourceLine" id="cb19-39" title="39">     <span class="co">*</span> 广告图片Image list</a>
<a class="sourceLine" id="cb19-40" title="40">     <span class="co">*</span></a>
<a class="sourceLine" id="cb19-41" title="41">     <span class="co">* @</span>return</a>
<a class="sourceLine" id="cb19-42" title="42">     <span class="co">*/</span></a>
<a class="sourceLine" id="cb19-43" title="43">    <span class="bu">List</span>&lt;TTImage&gt; <span class="fu">getImageList</span>();</a>
<a class="sourceLine" id="cb19-44" title="44"></a>
<a class="sourceLine" id="cb19-45" title="45">    <span class="co">/**</span></a>
<a class="sourceLine" id="cb19-46" title="46">     <span class="co">*</span> 得到Feed广告交互类型</a>
<a class="sourceLine" id="cb19-47" title="47">     <span class="co">*</span></a>
<a class="sourceLine" id="cb19-48" title="48">     <span class="co">* </span><span class="an">@return </span><span class="co">2:</span>在浏览器打开网页，3<span class="co">:</span>在app中打开，<span class="co">4:</span>下载应用，5<span class="co">:</span>拨打电话 其它：未知类型</a>
<a class="sourceLine" id="cb19-49" title="49">     <span class="co">*/</span></a>
<a class="sourceLine" id="cb19-50" title="50">    <span class="dt">int</span> <span class="fu">getInteractionType</span>();</a>
<a class="sourceLine" id="cb19-51" title="51"></a>
<a class="sourceLine" id="cb19-52" title="52"></a>
<a class="sourceLine" id="cb19-53" title="53">    <span class="co">/**</span></a>
<a class="sourceLine" id="cb19-54" title="54">     <span class="co">*</span> 得到Feed广告图片模式</a>
<a class="sourceLine" id="cb19-55" title="55">     <span class="co">*</span></a>
<a class="sourceLine" id="cb19-56" title="56">     <span class="co">* </span><span class="an">@return </span><span class="co">3</span> 大图 <span class="co">2小</span>图 <span class="co">4</span> 组图 <span class="co">5</span> 视频 其它：未知类型</a>
<a class="sourceLine" id="cb19-57" title="57">     <span class="co">*/</span></a>
<a class="sourceLine" id="cb19-58" title="58">    <span class="dt">int</span> <span class="fu">getImageMode</span>();</a>
<a class="sourceLine" id="cb19-59" title="59"></a>
<a class="sourceLine" id="cb19-60" title="60">    <span class="co">/**</span></a>
<a class="sourceLine" id="cb19-61" title="61">     <span class="co">*</span> 得到dislike dialog</a>
<a class="sourceLine" id="cb19-62" title="62">     <span class="co">*</span></a>
<a class="sourceLine" id="cb19-63" title="63">     <span class="co">* </span><span class="an">@param activity </span>建议传当前activity，否则可能会影响dislike对话框弹出</a>
<a class="sourceLine" id="cb19-64" title="64">     <span class="co">*</span> <span class="co">@</span>return</a>
<a class="sourceLine" id="cb19-65" title="65">     <span class="co">*/</span></a>
<a class="sourceLine" id="cb19-66" title="66">    TTAdDislike <span class="fu">getDislikeDialog</span>(Activity activity);</a>
<a class="sourceLine" id="cb19-67" title="67"></a>
<a class="sourceLine" id="cb19-68" title="68">    <span class="co">/**</span></a>
<a class="sourceLine" id="cb19-69" title="69">     <span class="co">*</span> 自定义dislike dialog</a>
<a class="sourceLine" id="cb19-70" title="70">     <span class="co">*</span></a>
<a class="sourceLine" id="cb19-71" title="71">     <span class="co">* </span><span class="an">@param dialog </span>自定义dialog，需要由外部传入</a>
<a class="sourceLine" id="cb19-72" title="72">     <span class="co">*</span> <span class="co">@</span>return</a>
<a class="sourceLine" id="cb19-73" title="73">     <span class="co">*/</span></a>
<a class="sourceLine" id="cb19-74" title="74">    TTAdDislike <span class="fu">getDislikeDialog</span>(TTDislikeDialogAbstract dialog);</a>
<a class="sourceLine" id="cb19-75" title="75"></a>
<a class="sourceLine" id="cb19-76" title="76">    <span class="co">/**</span></a>
<a class="sourceLine" id="cb19-77" title="77">     <span class="co">*</span> 获取下载状态控制器</a>
<a class="sourceLine" id="cb19-78" title="78">     <span class="co">*/</span></a>
<a class="sourceLine" id="cb19-79" title="79">    DownloadStatusController <span class="fu">getDownloadStatusController</span>();</a>
<a class="sourceLine" id="cb19-80" title="80"></a>
<a class="sourceLine" id="cb19-81" title="81">    <span class="co">/**</span></a>
<a class="sourceLine" id="cb19-82" title="82">     <span class="co">*</span> 注册可点击的View，click<span class="co">/</span>show会在内部完成</a>
<a class="sourceLine" id="cb19-83" title="83">     <span class="co">*</span></a>
<a class="sourceLine" id="cb19-84" title="84">     <span class="co">* </span><span class="an">@param container </span>渲染广告最外层的ViewGroup</a>
<a class="sourceLine" id="cb19-85" title="85">     <span class="co">*</span> <span class="an">@param clickView </span>可点击的View</a>
<a class="sourceLine" id="cb19-86" title="86">     <span class="co">*/</span></a>
<a class="sourceLine" id="cb19-87" title="87">    <span class="dt">void</span> <span class="fu">registerViewForInteraction</span>(<span class="at">@NonNull</span> ViewGroup container, <span class="at">@NonNull</span> <span class="bu">View</span> clickView, AdInteractionListener listener);</a>
<a class="sourceLine" id="cb19-88" title="88"></a>
<a class="sourceLine" id="cb19-89" title="89">    <span class="co">/**</span></a>
<a class="sourceLine" id="cb19-90" title="90">     <span class="co">*</span> 注册可点击的View，click<span class="co">/</span>show会在内部完成</a>
<a class="sourceLine" id="cb19-91" title="91">     <span class="co">*</span></a>
<a class="sourceLine" id="cb19-92" title="92">     <span class="co">* </span><span class="an">@param container </span>    渲染广告最外层的ViewGroup</a>
<a class="sourceLine" id="cb19-93" title="93">     <span class="co">*</span> <span class="an">@param clickViews </span>   可点击的View的列表</a>
<a class="sourceLine" id="cb19-94" title="94">     <span class="co">*</span> <span class="an">@param creativeViews </span>用于下载或者拨打电话的View</a>
<a class="sourceLine" id="cb19-95" title="95">     <span class="co">*/</span></a>
<a class="sourceLine" id="cb19-96" title="96">    <span class="dt">void</span> <span class="fu">registerViewForInteraction</span>(<span class="at">@NonNull</span> ViewGroup container, <span class="at">@NonNull</span> <span class="bu">List</span>&lt;<span class="bu">View</span>&gt; clickViews, <span class="at">@Nullable</span> <span class="bu">List</span>&lt;<span class="bu">View</span>&gt; creativeViews, AdInteractionListener listener);</a>
<a class="sourceLine" id="cb19-97" title="97"></a>
<a class="sourceLine" id="cb19-98" title="98">    <span class="co">/**</span></a>
<a class="sourceLine" id="cb19-99" title="99">     <span class="co">*</span> 注册可点击的View，click<span class="co">/</span>show会在内部完成，注册dislike按钮</a>
<a class="sourceLine" id="cb19-100" title="100">     <span class="co">*</span></a>
<a class="sourceLine" id="cb19-101" title="101">     <span class="co">* </span><span class="an">@param container </span>    渲染广告最外层的ViewGroup</a>
<a class="sourceLine" id="cb19-102" title="102">     <span class="co">*</span> <span class="an">@param clickViews </span>   可点击的View的列表</a>
<a class="sourceLine" id="cb19-103" title="103">     <span class="co">*</span> <span class="an">@param creativeViews </span>用于下载或者拨打电话的View</a>
<a class="sourceLine" id="cb19-104" title="104">     <span class="co">*</span> <span class="an">@param dislikeView </span>  dislike按钮</a>
<a class="sourceLine" id="cb19-105" title="105">     <span class="co">*</span> <span class="an">@param listener </span>     点击回调</a>
<a class="sourceLine" id="cb19-106" title="106">     <span class="co">*/</span></a>
<a class="sourceLine" id="cb19-107" title="107">    <span class="dt">void</span> <span class="fu">registerViewForInteraction</span>(<span class="at">@NonNull</span> ViewGroup container, <span class="at">@NonNull</span> <span class="bu">List</span>&lt;<span class="bu">View</span>&gt; clickViews, <span class="at">@Nullable</span> <span class="bu">List</span>&lt;<span class="bu">View</span>&gt; creativeViews, <span class="at">@Nullable</span> <span class="bu">View</span> dislikeView, AdInteractionListener listener);</a>
<a class="sourceLine" id="cb19-108" title="108"></a>
<a class="sourceLine" id="cb19-109" title="109">    <span class="co">/**</span></a>
<a class="sourceLine" id="cb19-110" title="110">     <span class="co">*</span> 设置下载监听器</a>
<a class="sourceLine" id="cb19-111" title="111">     <span class="co">*/</span></a>
<a class="sourceLine" id="cb19-112" title="112">    <span class="dt">void</span> <span class="fu">setDownloadListener</span>(TTAppDownloadListener downloadListener);</a>
<a class="sourceLine" id="cb19-113" title="113"></a>
<a class="sourceLine" id="cb19-114" title="114">    <span class="co">/**</span></a>
<a class="sourceLine" id="cb19-115" title="115">     <span class="co">*</span> 兼容下载类广告，使用activity申请权限</a>
<a class="sourceLine" id="cb19-116" title="116">     <span class="co">*/</span></a>
<a class="sourceLine" id="cb19-117" title="117">    <span class="dt">void</span> <span class="fu">setActivityForDownloadApp</span>(<span class="at">@NonNull</span> Activity activity);</a>
<a class="sourceLine" id="cb19-118" title="118"></a>
<a class="sourceLine" id="cb19-119" title="119">    <span class="co">/**</span></a>
<a class="sourceLine" id="cb19-120" title="120">     <span class="co">*</span> 获取广告的view<span class="co">,</span>如视频广告的view<span class="co">,</span>在广告平台可设置是否自动播放、是否静音等。</a>
<a class="sourceLine" id="cb19-121" title="121">     <span class="co">*</span></a>
<a class="sourceLine" id="cb19-122" title="122">     <span class="co">* @</span>return</a>
<a class="sourceLine" id="cb19-123" title="123">     <span class="co">*/</span></a>
<a class="sourceLine" id="cb19-124" title="124">    <span class="bu">View</span> <span class="fu">getAdView</span>();</a>
<a class="sourceLine" id="cb19-125" title="125"></a>
<a class="sourceLine" id="cb19-126" title="126">    <span class="co">/**</span></a>
<a class="sourceLine" id="cb19-127" title="127">     <span class="co">*</span> 信息流视频广告回调接口</a>
<a class="sourceLine" id="cb19-128" title="128">     <span class="co">*/</span></a>
<a class="sourceLine" id="cb19-129" title="129">    <span class="kw">interface</span> VideoAdListener {</a>
<a class="sourceLine" id="cb19-130" title="130"></a>
<a class="sourceLine" id="cb19-131" title="131">        <span class="co">/**</span></a>
<a class="sourceLine" id="cb19-132" title="132">         <span class="co">*</span> 视频广告加载成功</a>
<a class="sourceLine" id="cb19-133" title="133">         <span class="co">*</span></a>
<a class="sourceLine" id="cb19-134" title="134">         <span class="co">* </span><span class="an">@param ad</span></a>
<a class="sourceLine" id="cb19-135" title="135">         <span class="co">*/</span></a>
<a class="sourceLine" id="cb19-136" title="136">        <span class="dt">void</span> <span class="fu">onVideoLoad</span>(TTFeedAd ad);</a>
<a class="sourceLine" id="cb19-137" title="137"></a>
<a class="sourceLine" id="cb19-138" title="138">        <span class="co">/**</span></a>
<a class="sourceLine" id="cb19-139" title="139">         <span class="co">*</span> 视频广告加载失败（原生MediaPlayer内部提供的错误类型）</a>
<a class="sourceLine" id="cb19-140" title="140">         <span class="co">* </span><span class="an">@param errorCode </span>错误类型：</a>
<a class="sourceLine" id="cb19-141" title="141">         <span class="co">*</span>                  MEDIA_ERROR_UNKNOWN</a>
<a class="sourceLine" id="cb19-142" title="142">         <span class="co">*</span>                  MEDIA_ERROR_SERVER_DIED</a>
<a class="sourceLine" id="cb19-143" title="143">         <span class="co">*</span></a>
<a class="sourceLine" id="cb19-144" title="144">         <span class="co">*</span> <span class="an">@param extraCode </span>额外错误信息</a>
<a class="sourceLine" id="cb19-145" title="145">         <span class="co">*</span>                  MEDIA_ERROR_IO</a>
<a class="sourceLine" id="cb19-146" title="146">         <span class="co">*</span>                  MEDIA_ERROR_MALFORMED</a>
<a class="sourceLine" id="cb19-147" title="147">         <span class="co">*</span>                  MEDIA_ERROR_UNSUPPORTED</a>
<a class="sourceLine" id="cb19-148" title="148">         <span class="co">*</span>                  MEDIA_ERROR_TIMED_OUT</a>
<a class="sourceLine" id="cb19-149" title="149">         <span class="co">*</span>                  MEDIA_ERROR_SYSTEM</a>
<a class="sourceLine" id="cb19-150" title="150">         <span class="co">*</span></a>
<a class="sourceLine" id="cb19-151" title="151">         <span class="co">*/</span></a>
<a class="sourceLine" id="cb19-152" title="152">        <span class="dt">void</span> <span class="fu">onVideoError</span>(<span class="dt">int</span> errorCode, <span class="dt">int</span> extraCode);</a>
<a class="sourceLine" id="cb19-153" title="153"></a>
<a class="sourceLine" id="cb19-154" title="154">        <span class="co">/**</span></a>
<a class="sourceLine" id="cb19-155" title="155">         <span class="co">*</span> 视频广告播放回调</a>
<a class="sourceLine" id="cb19-156" title="156">         <span class="co">*</span></a>
<a class="sourceLine" id="cb19-157" title="157">         <span class="co">* </span><span class="an">@param ad</span></a>
<a class="sourceLine" id="cb19-158" title="158">         <span class="co">*/</span></a>
<a class="sourceLine" id="cb19-159" title="159">        <span class="dt">void</span> <span class="fu">onVideoAdStartPlay</span>(TTFeedAd ad);</a>
<a class="sourceLine" id="cb19-160" title="160"></a>
<a class="sourceLine" id="cb19-161" title="161">        <span class="co">/**</span></a>
<a class="sourceLine" id="cb19-162" title="162">         <span class="co">*</span> 视频广告暂停回调</a>
<a class="sourceLine" id="cb19-163" title="163">         <span class="co">*</span></a>
<a class="sourceLine" id="cb19-164" title="164">         <span class="co">* </span><span class="an">@param ad</span></a>
<a class="sourceLine" id="cb19-165" title="165">         <span class="co">*/</span></a>
<a class="sourceLine" id="cb19-166" title="166">        <span class="dt">void</span> <span class="fu">onVideoAdPaused</span>(TTFeedAd ad);</a>
<a class="sourceLine" id="cb19-167" title="167"></a>
<a class="sourceLine" id="cb19-168" title="168">        <span class="co">/**</span></a>
<a class="sourceLine" id="cb19-169" title="169">         <span class="co">*</span> 视频广告续播</a>
<a class="sourceLine" id="cb19-170" title="170">         <span class="co">*</span></a>
<a class="sourceLine" id="cb19-171" title="171">         <span class="co">* </span><span class="an">@param ad</span></a>
<a class="sourceLine" id="cb19-172" title="172">         <span class="co">*/</span></a>
<a class="sourceLine" id="cb19-173" title="173">        <span class="dt">void</span> <span class="fu">onVideoAdContinuePlay</span>(TTFeedAd ad);</a>
<a class="sourceLine" id="cb19-174" title="174">    }</a>
<a class="sourceLine" id="cb19-175" title="175"></a>
<a class="sourceLine" id="cb19-176" title="176"></a>
<a class="sourceLine" id="cb19-177" title="177">    <span class="dt">void</span> <span class="fu">setVideoAdListener</span>(VideoAdListener videoAdListener);</a>
<a class="sourceLine" id="cb19-178" title="178"></a>
<a class="sourceLine" id="cb19-179" title="179">}</a>
<a class="sourceLine" id="cb19-180" title="180"></a></code></pre></div>
<h4 id="加载原生信息流广告">2.4.2 加载原生信息流广告</h4>
<p>接入方可调用TTAdNative.loadFeedAd(AdSlot adSlot, FeedAdListener listener)方法异步加载信息流广告，adSlot为用户请求的信息，FeedAdListener为加载成功、失败的回调监听器。示例如下：</p>
<div class="sourceCode" id="cb20"><pre class="sourceCode java"><code class="sourceCode java"><a class="sourceLine" id="cb20-1" title="1">mTTAdNative.<span class="fu">loadFeedAd</span>(adSlot, <span class="kw">new</span> TTAdNative.<span class="fu">FeedAdListener</span>() {</a>
<a class="sourceLine" id="cb20-2" title="2">    <span class="at">@Override</span></a>
<a class="sourceLine" id="cb20-3" title="3">    <span class="kw">public</span> <span class="dt">void</span> <span class="fu">onError</span>(<span class="dt">int</span> code, <span class="bu">String</span> message) {</a>
<a class="sourceLine" id="cb20-4" title="4">        <span class="co">//加载失败的回调，详见3.1错误码说明</span></a>
<a class="sourceLine" id="cb20-5" title="5">        Toast.<span class="fu">makeText</span>(FeedActivity.<span class="fu">this</span>, message, Toast.<span class="fu">LENGTH_SHORT</span>).<span class="fu">show</span>();</a>
<a class="sourceLine" id="cb20-6" title="6">    }</a>
<a class="sourceLine" id="cb20-7" title="7"></a>
<a class="sourceLine" id="cb20-8" title="8">    <span class="at">@Override</span></a>
<a class="sourceLine" id="cb20-9" title="9">    <span class="kw">public</span> <span class="dt">void</span> <span class="fu">onFeedAdLoad</span>(<span class="bu">List</span>&lt;TTFeedAd&gt; ads) {</a>
<a class="sourceLine" id="cb20-10" title="10">        <span class="co">//加载成功的回调 请确保您的代码足够健壮，可以处理异常情况；</span></a>
<a class="sourceLine" id="cb20-11" title="11">       <span class="kw">if</span> (ads == <span class="kw">null</span> || ads.<span class="fu">isEmpty</span>()) {</a>
<a class="sourceLine" id="cb20-12" title="12">            Toast.<span class="fu">makeText</span>(FeedActivity.<span class="fu">this</span>, <span class="st">&quot;on FeedAdLoaded: ad is null!&quot;</span>, Toast.<span class="fu">LENGTH_SHORT</span>).<span class="fu">show</span>();</a>
<a class="sourceLine" id="cb20-13" title="13">            <span class="kw">return</span>;</a>
<a class="sourceLine" id="cb20-14" title="14">        }</a>
<a class="sourceLine" id="cb20-15" title="15">        <span class="kw">for</span> (<span class="dt">int</span> i = <span class="dv">0</span>; i &lt; ads.<span class="fu">size</span>(); i++) {</a>
<a class="sourceLine" id="cb20-16" title="16">            mData.<span class="fu">set</span>((AD_POSITION + i) % mData.<span class="fu">size</span>(), ads.<span class="fu">get</span>(i));</a>
<a class="sourceLine" id="cb20-17" title="17">        }</a>
<a class="sourceLine" id="cb20-18" title="18">        myAdapter.<span class="fu">notifyDataSetChanged</span>();</a>
<a class="sourceLine" id="cb20-19" title="19">    }</a>
<a class="sourceLine" id="cb20-20" title="20">});</a></code></pre></div>
<p>加载信息流广告的例子详见Demo中的FeedActivity类，以及/res/layout/下的listitem_ad_pic.xml文件。</p>
<h4 id="原生信息流视频广告回调">2.4.3 原生信息流视频广告回调</h4>
<p>如果需要额外的视频回调操作，如视频加载状态，暂停播放，续播等操作可以实现VideoAdListener接口</p>
<div class="sourceCode" id="cb21"><pre class="sourceCode java"><code class="sourceCode java"><a class="sourceLine" id="cb21-1" title="1">ttFeedAd.<span class="fu">setVideoAdListener</span>(<span class="kw">new</span> TTFeedAd.<span class="fu">VideoAdListener</span>() {</a>
<a class="sourceLine" id="cb21-2" title="2">        <span class="at">@Override</span></a>
<a class="sourceLine" id="cb21-3" title="3">        <span class="kw">public</span> <span class="dt">void</span> <span class="fu">onVideoLoad</span>(TTFeedAd ad) {</a>
<a class="sourceLine" id="cb21-4" title="4">            <span class="kw">if</span> (ad != <span class="kw">null</span>) {</a>
<a class="sourceLine" id="cb21-5" title="5">                Log.<span class="fu">d</span>(<span class="st">&quot;ad&quot;</span>,<span class="st">&quot;视频加载成功&quot;</span>);</a>
<a class="sourceLine" id="cb21-6" title="6">            }</a>
<a class="sourceLine" id="cb21-7" title="7">        }</a>
<a class="sourceLine" id="cb21-8" title="8"></a>
<a class="sourceLine" id="cb21-9" title="9">        <span class="at">@Override</span></a>
<a class="sourceLine" id="cb21-10" title="10">        <span class="kw">public</span> <span class="dt">void</span> <span class="fu">onVideoError</span>(<span class="dt">int</span> errorCode, <span class="dt">int</span> extraCode) {</a>
<a class="sourceLine" id="cb21-11" title="11">                Log.<span class="fu">d</span>(<span class="st">&quot;ad&quot;</span>,<span class="st">&quot;视频播放错误：errorCode=&quot;</span>+errorCode+<span class="st">&quot;,extraCode=&quot;</span>+extraCode);</a>
<a class="sourceLine" id="cb21-12" title="12">        }</a>
<a class="sourceLine" id="cb21-13" title="13"></a>
<a class="sourceLine" id="cb21-14" title="14">        <span class="at">@Override</span></a>
<a class="sourceLine" id="cb21-15" title="15">        <span class="kw">public</span> <span class="dt">void</span> <span class="fu">onVideoAdStartPlay</span>(TTFeedAd ad) {</a>
<a class="sourceLine" id="cb21-16" title="16">            <span class="kw">if</span> (ad != <span class="kw">null</span>) {</a>
<a class="sourceLine" id="cb21-17" title="17">                Log.<span class="fu">d</span>(<span class="st">&quot;ad&quot;</span>,<span class="st">&quot;视频开始播放&quot;</span>);</a>
<a class="sourceLine" id="cb21-18" title="18"></a>
<a class="sourceLine" id="cb21-19" title="19">            }</a>
<a class="sourceLine" id="cb21-20" title="20">        }</a>
<a class="sourceLine" id="cb21-21" title="21"></a>
<a class="sourceLine" id="cb21-22" title="22">        <span class="at">@Override</span></a>
<a class="sourceLine" id="cb21-23" title="23">        <span class="kw">public</span> <span class="dt">void</span> <span class="fu">onVideoAdPaused</span>(TTFeedAd ad) {</a>
<a class="sourceLine" id="cb21-24" title="24">            <span class="kw">if</span> (ad != <span class="kw">null</span>) {</a>
<a class="sourceLine" id="cb21-25" title="25">                Log.<span class="fu">d</span>(<span class="st">&quot;ad&quot;</span>,<span class="st">&quot;视频暂停播放&quot;</span>);</a>
<a class="sourceLine" id="cb21-26" title="26"></a>
<a class="sourceLine" id="cb21-27" title="27">            }</a>
<a class="sourceLine" id="cb21-28" title="28">        }</a>
<a class="sourceLine" id="cb21-29" title="29"></a>
<a class="sourceLine" id="cb21-30" title="30">        <span class="at">@Override</span></a>
<a class="sourceLine" id="cb21-31" title="31">        <span class="kw">public</span> <span class="dt">void</span> <span class="fu">onVideoAdContinuePlay</span>(TTFeedAd ad) {</a>
<a class="sourceLine" id="cb21-32" title="32">            <span class="kw">if</span> (ad != <span class="kw">null</span>) {</a>
<a class="sourceLine" id="cb21-33" title="33">                Log.<span class="fu">d</span>(<span class="st">&quot;ad&quot;</span>,<span class="st">&quot;视频继续播放&quot;</span>);</a>
<a class="sourceLine" id="cb21-34" title="34"></a>
<a class="sourceLine" id="cb21-35" title="35">            }</a>
<a class="sourceLine" id="cb21-36" title="36">        }</a>
<a class="sourceLine" id="cb21-37" title="37">    });</a></code></pre></div>
<h4 id="注册可点击的view">2.4.4 注册可点击的View</h4>
<p>在加载到信息流广告后，接入方需要注册在信息流广告中可以点击的View，即TTFeedAd.registerViewForInteraction()方法，以实现广告的功能交互及计费。包含图文点击区域的注册和附加创意按钮点击区域的注册。对于落地页广告，用户点击图文广告区域会跳转到相应的落地页，点击附加创意区域会进行电话拨打、应用下载等操作。 <strong>注意：如果需要点击图文区域也能进行下载或者拨打电话动作，请将图文区域的view传入creativeViewList，详细代码如下</strong></p>
<p>注册点击View示例的示例代码如下，该示例片段在BaseAdapter中的getView()方法中调用。</p>
<pre><code>private void bindData(View convertView, final AdViewHolder adViewHolder, TTFeedAd ad) {
    // 可以被点击的view, 也可以把convertView放进来意味整个item可被点击，点击会跳转到落地页
    List&lt;View&gt; clickViewList = new ArrayList&lt;View&gt;();
    clickViewList.add(convertView);
    // 创意点击区域的view 点击根据不同的创意进行下载或拨打电话动作
    //如果需要点击图文区域也能进行下载或者拨打电话动作，请将图文区域的view传入creativeViewList
    List&lt;View&gt; creativeViewList = new ArrayList&lt;View&gt;();
    creativeViewList.add(adViewHolder.mCreativeButton);
    // 注册普通点击区域，创意点击区域。重要! 这个涉及到广告计费及交互，必须正确调用。convertView必须使用ViewGroup。
    ad.registerViewForInteraction((ViewGroup) convertView, clickViewList, creativeViewList, new TTNativeAd.AdInteractionListener() {
        @Override
        public void onAdClicked(View view, TTNativeAd ad) {
            // 点击普通区域的回调
            Toast.makeText(mContext, &quot;广告被点击&quot;, Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onAdCreativeClick(View view, TTNativeAd ad) {
              // 点击创意区域的回调
            Toast.makeText(mContext, &quot;广告创意按钮被点击&quot;, Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onAdShow(TTNativeAd ad) {
           // 广告曝光展示的回调
            TToast.show(mContext, &quot;广告&quot; + ad.getTitle() + &quot;展示&quot;);
        }
    });
    ...</code></pre>
<p>详见Demo中的FeedActivity及/res/layout/下的listitem_ad_pic.xml。</p>
<h3 id="接入banner广告ttbannerad">2.5 接入Banner广告（TTBannerAd）</h3>
<p>SDK为接入方提供了Banner类型的广告，Banner广告为一张图片的View（TTBannerAd.getBannerView），此View的宽高默认为match_parent，用户可以自行定义宽高或通过设置父布局的宽高的方式来限定Banner广告的大小（注：Banner广告的宽高请尽量与adSlot中设置的宽高比例接近，以避免过多非等比例的拉伸）。</p>
<p>Banner广告可支持的多种尺寸比例，具体如下：</p>
<p>尺寸：600*300，600*400，600*500，600*260，600*90，600*150，640*100，690*388</p>
<h4 id="ttbanner广告接口说明">2.5.1 TTBanner广告接口说明</h4>
<div class="sourceCode" id="cb23"><pre class="sourceCode java"><code class="sourceCode java"><a class="sourceLine" id="cb23-1" title="1"><span class="kw">public</span> <span class="kw">interface</span> TTBannerAd {</a>
<a class="sourceLine" id="cb23-2" title="2"></a>
<a class="sourceLine" id="cb23-3" title="3">    <span class="co">/**</span></a>
<a class="sourceLine" id="cb23-4" title="4">     <span class="co">*</span> 得到Banner广告</a>
<a class="sourceLine" id="cb23-5" title="5">     <span class="co">*</span></a>
<a class="sourceLine" id="cb23-6" title="6">     <span class="co">* @</span>return</a>
<a class="sourceLine" id="cb23-7" title="7">     <span class="co">*/</span></a>
<a class="sourceLine" id="cb23-8" title="8">    <span class="bu">View</span> <span class="fu">getBannerView</span>();</a>
<a class="sourceLine" id="cb23-9" title="9"></a>
<a class="sourceLine" id="cb23-10" title="10">    <span class="co">/**</span></a>
<a class="sourceLine" id="cb23-11" title="11">     <span class="co">*</span> 注册Banner广告交互回调</a>
<a class="sourceLine" id="cb23-12" title="12">     <span class="co">*</span></a>
<a class="sourceLine" id="cb23-13" title="13">     <span class="co">* </span><span class="an">@param listener </span>监听器</a>
<a class="sourceLine" id="cb23-14" title="14">     <span class="co">*/</span></a>
<a class="sourceLine" id="cb23-15" title="15">    <span class="dt">void</span> <span class="fu">setBannerInteractionListener</span>(AdInteractionListener listener);</a>
<a class="sourceLine" id="cb23-16" title="16"></a>
<a class="sourceLine" id="cb23-17" title="17">    <span class="co">/**</span></a>
<a class="sourceLine" id="cb23-18" title="18">     <span class="co">*</span> 注册Banner广告的下载回调</a>
<a class="sourceLine" id="cb23-19" title="19">     <span class="co">*</span></a>
<a class="sourceLine" id="cb23-20" title="20">     <span class="co">* </span><span class="an">@param downloadListener </span>下载回调监听器</a>
<a class="sourceLine" id="cb23-21" title="21">     <span class="co">*/</span></a>
<a class="sourceLine" id="cb23-22" title="22">    <span class="dt">void</span> <span class="fu">setDownloadListener</span>(TTAppDownloadListener downloadListener);</a>
<a class="sourceLine" id="cb23-23" title="23"></a>
<a class="sourceLine" id="cb23-24" title="24">    <span class="co">/**</span></a>
<a class="sourceLine" id="cb23-25" title="25">     <span class="co">*</span> 得到Banner广告的交互类型</a>
<a class="sourceLine" id="cb23-26" title="26">     <span class="co">*</span></a>
<a class="sourceLine" id="cb23-27" title="27">     <span class="co">* </span><span class="an">@return </span><span class="co">2在</span>浏览器内打开 （普通类型）3落地页（普通类型），<span class="co">4:</span>应用下载，5:拨打电话 <span class="co">-1</span> 未知类型</a>
<a class="sourceLine" id="cb23-28" title="28">     <span class="co">*/</span></a>
<a class="sourceLine" id="cb23-29" title="29">    <span class="dt">int</span> <span class="fu">getInteractionType</span>();</a>
<a class="sourceLine" id="cb23-30" title="30"></a>
<a class="sourceLine" id="cb23-31" title="31">    <span class="co">/**</span></a>
<a class="sourceLine" id="cb23-32" title="32">     <span class="co">*</span> 设置在banner中使用穿山甲中 tt_dislike_icon ico以及逻辑</a>
<a class="sourceLine" id="cb23-33" title="33">     <span class="co">*</span></a>
<a class="sourceLine" id="cb23-34" title="34">     <span class="co">* </span><span class="an">@param dislikeInteractionCallback </span>dislike选择结果回调</a>
<a class="sourceLine" id="cb23-35" title="35">     <span class="co">*/</span></a>
<a class="sourceLine" id="cb23-36" title="36">    <span class="dt">void</span> <span class="fu">setShowDislikeIcon</span>(TTAdDislike.<span class="fu">DislikeInteractionCallback</span> dislikeInteractionCallback);</a>
<a class="sourceLine" id="cb23-37" title="37"></a>
<a class="sourceLine" id="cb23-38" title="38">    <span class="co">/**</span></a>
<a class="sourceLine" id="cb23-39" title="39">     <span class="co">*</span> 得到dislike dialog</a>
<a class="sourceLine" id="cb23-40" title="40">     <span class="co">*</span></a>
<a class="sourceLine" id="cb23-41" title="41">     <span class="co">* </span><span class="an">@param dislikeInteractionCallback </span>dislike选择结果回调</a>
<a class="sourceLine" id="cb23-42" title="42">     <span class="co">*/</span></a>
<a class="sourceLine" id="cb23-43" title="43">    TTAdDislike <span class="fu">getDislikeDialog</span>(TTAdDislike.<span class="fu">DislikeInteractionCallback</span> dislikeInteractionCallback);</a>
<a class="sourceLine" id="cb23-44" title="44"></a>
<a class="sourceLine" id="cb23-45" title="45">    <span class="co">/**</span></a>
<a class="sourceLine" id="cb23-46" title="46">     <span class="co">*</span> 自定义dislike dialog</a>
<a class="sourceLine" id="cb23-47" title="47">     <span class="co">*</span></a>
<a class="sourceLine" id="cb23-48" title="48">     <span class="co">* </span><span class="an">@param dialog </span>自定义dialog，需要由外部传入</a>
<a class="sourceLine" id="cb23-49" title="49">     <span class="co">*</span> <span class="co">@</span>return</a>
<a class="sourceLine" id="cb23-50" title="50">     <span class="co">*/</span></a>
<a class="sourceLine" id="cb23-51" title="51">    TTAdDislike <span class="fu">getDislikeDialog</span>(TTDislikeDialogAbstract dialog);</a>
<a class="sourceLine" id="cb23-52" title="52"></a>
<a class="sourceLine" id="cb23-53" title="53">    <span class="co">/**</span></a>
<a class="sourceLine" id="cb23-54" title="54">     <span class="co">*</span> 设置Banner广告轮播的间隔时间，如果不设置则默认不开启轮播</a>
<a class="sourceLine" id="cb23-55" title="55">     <span class="co">*</span></a>
<a class="sourceLine" id="cb23-56" title="56">     <span class="co">* </span><span class="an">@param intervalTime </span>Banner广告轮播的间隔时间，允许值在<span class="co">30</span> <span class="co">*</span> <span class="co">1000</span> <span class="co">~</span> <span class="co">120</span> <span class="co">*</span> <span class="co">1000之间</span></a>
<a class="sourceLine" id="cb23-57" title="57">     <span class="co">*/</span></a>
<a class="sourceLine" id="cb23-58" title="58">    <span class="dt">void</span> <span class="fu">setSlideIntervalTime</span>(<span class="dt">int</span> intervalTime);</a>
<a class="sourceLine" id="cb23-59" title="59"></a>
<a class="sourceLine" id="cb23-60" title="60">    <span class="co">/**</span></a>
<a class="sourceLine" id="cb23-61" title="61">     <span class="co">*</span> Banner广告交互监听器</a>
<a class="sourceLine" id="cb23-62" title="62">     <span class="co">*/</span></a>
<a class="sourceLine" id="cb23-63" title="63">    <span class="kw">interface</span> AdInteractionListener {</a>
<a class="sourceLine" id="cb23-64" title="64"></a>
<a class="sourceLine" id="cb23-65" title="65">        <span class="co">/**</span></a>
<a class="sourceLine" id="cb23-66" title="66">         <span class="co">*</span> Banner广告的点击回调</a>
<a class="sourceLine" id="cb23-67" title="67">         <span class="co">* </span><span class="an">@param view </span>Banner广告</a>
<a class="sourceLine" id="cb23-68" title="68">         <span class="co">*</span> <span class="an">@param type </span>Banner广告的交互类型</a>
<a class="sourceLine" id="cb23-69" title="69">         <span class="co">*/</span></a>
<a class="sourceLine" id="cb23-70" title="70">        <span class="dt">void</span> <span class="fu">onAdClicked</span>(<span class="bu">View</span> view, <span class="dt">int</span> type);</a>
<a class="sourceLine" id="cb23-71" title="71"></a>
<a class="sourceLine" id="cb23-72" title="72">        <span class="co">/**</span></a>
<a class="sourceLine" id="cb23-73" title="73">         <span class="co">*</span> Banner广告的展示回调 每个广告仅回调一次</a>
<a class="sourceLine" id="cb23-74" title="74">         <span class="co">* </span><span class="an">@param view </span>Banner广告</a>
<a class="sourceLine" id="cb23-75" title="75">         <span class="co">*</span> <span class="an">@param type </span>Banner广告的交互类型</a>
<a class="sourceLine" id="cb23-76" title="76">         <span class="co">*/</span></a>
<a class="sourceLine" id="cb23-77" title="77">        <span class="dt">void</span> <span class="fu">onAdShow</span>(<span class="bu">View</span> view, <span class="dt">int</span> type);</a>
<a class="sourceLine" id="cb23-78" title="78"></a>
<a class="sourceLine" id="cb23-79" title="79">    }</a>
<a class="sourceLine" id="cb23-80" title="80">}</a></code></pre></div>
<h4 id="加载banner广告">2.5.2 加载Banner广告</h4>
<p>接入方可通过调用TTAdNativie.loadBannerAd(AdSlot adSlot, BannerAdListener listener)方法来异步加载Banner广告，adSlot为请求的信息，TTAdNative.BannerAdListener为Banner广告加载成功、失败的回调。</p>
<div class="sourceCode" id="cb24"><pre class="sourceCode java"><code class="sourceCode java"><a class="sourceLine" id="cb24-1" title="1">mTTAdNative.<span class="fu">loadBannerAd</span>(adSlot, <span class="kw">new</span> TTAdNative.<span class="fu">BannerAdListener</span>() {</a>
<a class="sourceLine" id="cb24-2" title="2"></a>
<a class="sourceLine" id="cb24-3" title="3">    <span class="at">@Override</span></a>
<a class="sourceLine" id="cb24-4" title="4">    <span class="kw">public</span> <span class="dt">void</span> <span class="fu">onError</span>(<span class="dt">int</span> code, <span class="bu">String</span> message) {</a>
<a class="sourceLine" id="cb24-5" title="5">        <span class="co">//加载失败的回调 详见3.1错误码说明</span></a>
<a class="sourceLine" id="cb24-6" title="6">        Toast.<span class="fu">makeText</span>(BannerActivity.<span class="fu">this</span>, <span class="st">&quot;load error : &quot;</span> + code + <span class="st">&quot;, &quot;</span> + message, Toast.<span class="fu">LENGTH_SHORT</span>).<span class="fu">show</span>();</a>
<a class="sourceLine" id="cb24-7" title="7">    }</a>
<a class="sourceLine" id="cb24-8" title="8"></a>
<a class="sourceLine" id="cb24-9" title="9">    <span class="at">@Override</span></a>
<a class="sourceLine" id="cb24-10" title="10">    <span class="kw">public</span> <span class="dt">void</span> <span class="fu">onBannerAdLoad</span>(TTBannerAd ad) {</a>
<a class="sourceLine" id="cb24-11" title="11">        <span class="co">// 加载成功的回调，接入方可在此处做广告的展示，请确保您的代码足够健壮，能够处理异常情况；</span></a>
<a class="sourceLine" id="cb24-12" title="12">        <span class="bu">View</span> bannerView = ad.<span class="fu">getBannerView</span>();</a>
<a class="sourceLine" id="cb24-13" title="13">        <span class="kw">if</span> (bannerView == <span class="kw">null</span>) {</a>
<a class="sourceLine" id="cb24-14" title="14">            <span class="kw">return</span>;</a>
<a class="sourceLine" id="cb24-15" title="15">        }</a>
<a class="sourceLine" id="cb24-16" title="16">        mBannerContainer.<span class="fu">removeAllViews</span>();</a>
<a class="sourceLine" id="cb24-17" title="17">        mBannerContainer.<span class="fu">addView</span>(bannerView);</a>
<a class="sourceLine" id="cb24-18" title="18">    }</a>
<a class="sourceLine" id="cb24-19" title="19">});</a></code></pre></div>
<p>具体示例详见Demo中的BannerActivity。</p>
<h3 id="接入开屏广告ttsplashad">2.6 接入开屏广告（TTSplashAd）</h3>
<p>SDK为接入方提供了开屏广告，开屏广告建议为用户在进入App时展示的全屏广告。开屏广告为一个View，宽高默认为match_parent,注意开屏广告view：width &gt;=70%屏幕宽；height &gt;=50%屏幕高 ，否则会影响计费。</p>
<p>开屏广告可支持的尺寸：图片尺寸传入与展示区域大小保持一致，避免素材变形</p>
<p>开屏广告场景也支持个性化模板广告，开发者需要在穿山甲平台申请支持该特性的广告位id，且在构造AdSlot对象时，调用setExpressViewAcceptedSize传入期望的模板广告尺寸大小，详见demo示例。</p>
<h4 id="ttsplashad广告接口说明">2.6.1 TTSplashAd广告接口说明：</h4>
<div class="sourceCode" id="cb25"><pre class="sourceCode java"><code class="sourceCode java"><a class="sourceLine" id="cb25-1" title="1"><span class="kw">public</span> <span class="kw">interface</span> TTSplashAd {</a>
<a class="sourceLine" id="cb25-2" title="2"></a>
<a class="sourceLine" id="cb25-3" title="3">  <span class="co">/**</span></a>
<a class="sourceLine" id="cb25-4" title="4">   <span class="co">*</span> 得到开屏广告</a>
<a class="sourceLine" id="cb25-5" title="5">   <span class="co">*</span></a>
<a class="sourceLine" id="cb25-6" title="6">   <span class="co">* @</span>return</a>
<a class="sourceLine" id="cb25-7" title="7">   <span class="co">*/</span></a>
<a class="sourceLine" id="cb25-8" title="8">  <span class="at">@NonNull</span></a>
<a class="sourceLine" id="cb25-9" title="9">  <span class="bu">View</span> <span class="fu">getSplashView</span>();</a>
<a class="sourceLine" id="cb25-10" title="10"></a>
<a class="sourceLine" id="cb25-11" title="11">  <span class="co">/**</span></a>
<a class="sourceLine" id="cb25-12" title="12">   <span class="co">*</span> 得到Splash广告的交互类型</a>
<a class="sourceLine" id="cb25-13" title="13">   <span class="co">*</span></a>
<a class="sourceLine" id="cb25-14" title="14">   <span class="co">* </span><span class="an">@return </span><span class="co">2在</span>浏览器内打开 （普通类型）3落地页（普通类型），<span class="co">5:</span>拨打电话 <span class="co">-1</span> 未知类型</a>
<a class="sourceLine" id="cb25-15" title="15">   <span class="co">*/</span></a>
<a class="sourceLine" id="cb25-16" title="16">  <span class="dt">int</span> <span class="fu">getInteractionType</span>();</a>
<a class="sourceLine" id="cb25-17" title="17"></a>
<a class="sourceLine" id="cb25-18" title="18">  <span class="co">/**</span></a>
<a class="sourceLine" id="cb25-19" title="19">   <span class="co">*</span> 注册Splash广告交互回调</a>
<a class="sourceLine" id="cb25-20" title="20">   <span class="co">*</span></a>
<a class="sourceLine" id="cb25-21" title="21">   <span class="co">* </span><span class="an">@param listener </span>监听器</a>
<a class="sourceLine" id="cb25-22" title="22">   <span class="co">*/</span></a>
<a class="sourceLine" id="cb25-23" title="23">  <span class="dt">void</span> <span class="fu">setSplashInteractionListener</span>(AdInteractionListener listener);</a>
<a class="sourceLine" id="cb25-24" title="24"></a>
<a class="sourceLine" id="cb25-25" title="25">  <span class="kw">interface</span> AdInteractionListener {</a>
<a class="sourceLine" id="cb25-26" title="26">      <span class="co">/**</span></a>
<a class="sourceLine" id="cb25-27" title="27">       <span class="co">*</span> Splash广告的点击回调</a>
<a class="sourceLine" id="cb25-28" title="28">       <span class="co">*</span></a>
<a class="sourceLine" id="cb25-29" title="29">       <span class="co">* </span><span class="an">@param view </span>Splash广告</a>
<a class="sourceLine" id="cb25-30" title="30">       <span class="co">*</span> <span class="an">@param type </span>Splash广告的交互类型</a>
<a class="sourceLine" id="cb25-31" title="31">       <span class="co">*/</span></a>
<a class="sourceLine" id="cb25-32" title="32">      <span class="dt">void</span> <span class="fu">onAdClicked</span>(<span class="bu">View</span> view, <span class="dt">int</span> type);</a>
<a class="sourceLine" id="cb25-33" title="33"></a>
<a class="sourceLine" id="cb25-34" title="34">      <span class="co">/**</span></a>
<a class="sourceLine" id="cb25-35" title="35">       <span class="co">*</span> Splash广告的展示回调 每个广告仅回调一次</a>
<a class="sourceLine" id="cb25-36" title="36">       <span class="co">*</span></a>
<a class="sourceLine" id="cb25-37" title="37">       <span class="co">* </span><span class="an">@param view </span>Splash广告</a>
<a class="sourceLine" id="cb25-38" title="38">       <span class="co">*</span> <span class="an">@param type </span>Splash广告的交互类型</a>
<a class="sourceLine" id="cb25-39" title="39">       <span class="co">*/</span></a>
<a class="sourceLine" id="cb25-40" title="40">      <span class="dt">void</span> <span class="fu">onAdShow</span>(<span class="bu">View</span> view, <span class="dt">int</span> type);</a>
<a class="sourceLine" id="cb25-41" title="41"></a>
<a class="sourceLine" id="cb25-42" title="42">      <span class="co">/**</span></a>
<a class="sourceLine" id="cb25-43" title="43">       <span class="co">*</span> 点击跳过时回调</a>
<a class="sourceLine" id="cb25-44" title="44">       <span class="co">*/</span></a>
<a class="sourceLine" id="cb25-45" title="45">      <span class="dt">void</span> <span class="fu">onAdSkip</span>();</a>
<a class="sourceLine" id="cb25-46" title="46"></a>
<a class="sourceLine" id="cb25-47" title="47">      <span class="co">/**</span></a>
<a class="sourceLine" id="cb25-48" title="48">       <span class="co">*</span> 广告播放时间结束</a>
<a class="sourceLine" id="cb25-49" title="49">       <span class="co">*/</span></a>
<a class="sourceLine" id="cb25-50" title="50">      <span class="dt">void</span> <span class="fu">onAdTimeOver</span>();</a>
<a class="sourceLine" id="cb25-51" title="51">  }</a>
<a class="sourceLine" id="cb25-52" title="52">}</a></code></pre></div>
<h4 id="加载开屏广告">2.6.2 加载开屏广告</h4>
<p>接入方可调用TTAdNative.loadSplashAd(AdSlot adSlot, SplashAdListener listener, int timeOut)异步加载开屏广告。adslot为请求广告的信息，SplashAdListener为广告加载成功或失败的回调，timeOut为加载开屏广告允许的最长时间（注：建议timeOut &gt; 3000ms）。调用示例如下：</p>
<div class="sourceCode" id="cb26"><pre class="sourceCode java"><code class="sourceCode java"><a class="sourceLine" id="cb26-1" title="1">mTTAdNative.<span class="fu">loadSplashAd</span>(adSlot, <span class="kw">new</span> TTAdNative.<span class="fu">SplashAdListener</span>() {</a>
<a class="sourceLine" id="cb26-2" title="2">    <span class="at">@Override</span></a>
<a class="sourceLine" id="cb26-3" title="3">    <span class="at">@MainThread</span></a>
<a class="sourceLine" id="cb26-4" title="4">    <span class="kw">public</span> <span class="dt">void</span> <span class="fu">onError</span>(<span class="dt">int</span> code, <span class="bu">String</span> message) {</a>
<a class="sourceLine" id="cb26-5" title="5">        Log.<span class="fu">d</span>(TAG, message);</a>
<a class="sourceLine" id="cb26-6" title="6">        mHasLoaded = <span class="kw">true</span>;</a>
<a class="sourceLine" id="cb26-7" title="7">        <span class="fu">showToast</span>(message);</a>
<a class="sourceLine" id="cb26-8" title="8">        <span class="fu">goToMainActivity</span>();</a>
<a class="sourceLine" id="cb26-9" title="9">    }</a>
<a class="sourceLine" id="cb26-10" title="10"></a>
<a class="sourceLine" id="cb26-11" title="11">    <span class="at">@Override</span></a>
<a class="sourceLine" id="cb26-12" title="12">    <span class="at">@MainThread</span></a>
<a class="sourceLine" id="cb26-13" title="13">    <span class="kw">public</span> <span class="dt">void</span> <span class="fu">onTimeout</span>() {</a>
<a class="sourceLine" id="cb26-14" title="14">        mHasLoaded = <span class="kw">true</span>;</a>
<a class="sourceLine" id="cb26-15" title="15">        <span class="fu">showToast</span>(<span class="st">&quot;开屏广告加载超时&quot;</span>);</a>
<a class="sourceLine" id="cb26-16" title="16">        <span class="fu">goToMainActivity</span>();</a>
<a class="sourceLine" id="cb26-17" title="17">    }</a>
<a class="sourceLine" id="cb26-18" title="18"></a>
<a class="sourceLine" id="cb26-19" title="19">    <span class="at">@Override</span></a>
<a class="sourceLine" id="cb26-20" title="20">    <span class="at">@MainThread</span></a>
<a class="sourceLine" id="cb26-21" title="21">    <span class="kw">public</span> <span class="dt">void</span> <span class="fu">onSplashAdLoad</span>(TTSplashAd ad) {</a>
<a class="sourceLine" id="cb26-22" title="22">        Log.<span class="fu">d</span>(TAG, <span class="st">&quot;开屏广告请求成功&quot;</span>);</a>
<a class="sourceLine" id="cb26-23" title="23">        mHasLoaded = <span class="kw">true</span>;</a>
<a class="sourceLine" id="cb26-24" title="24">        mHandler.<span class="fu">removeCallbacksAndMessages</span>(<span class="kw">null</span>);</a>
<a class="sourceLine" id="cb26-25" title="25">        <span class="kw">if</span> (ad == <span class="kw">null</span>) {</a>
<a class="sourceLine" id="cb26-26" title="26">            <span class="kw">return</span>;</a>
<a class="sourceLine" id="cb26-27" title="27">        }</a>
<a class="sourceLine" id="cb26-28" title="28">        <span class="co">//获取SplashView</span></a>
<a class="sourceLine" id="cb26-29" title="29">        <span class="bu">View</span> view = ad.<span class="fu">getSplashView</span>();</a>
<a class="sourceLine" id="cb26-30" title="30"></a>
<a class="sourceLine" id="cb26-31" title="31">        mSplashContainer.<span class="fu">removeAllViews</span>();</a>
<a class="sourceLine" id="cb26-32" title="32">        <span class="co">//把SplashView 添加到ViewGroup中</span></a>
<a class="sourceLine" id="cb26-33" title="33">        mSplashContainer.<span class="fu">addView</span>(view);</a>
<a class="sourceLine" id="cb26-34" title="34">        <span class="co">//设置SplashView的交互监听器</span></a>
<a class="sourceLine" id="cb26-35" title="35">        ad.<span class="fu">setSplashInteractionListener</span>(<span class="kw">new</span> TTSplashAd.<span class="fu">AdInteractionListener</span>() {</a>
<a class="sourceLine" id="cb26-36" title="36">            <span class="at">@Override</span></a>
<a class="sourceLine" id="cb26-37" title="37">            <span class="kw">public</span> <span class="dt">void</span> <span class="fu">onAdClicked</span>(<span class="bu">View</span> view, <span class="dt">int</span> type) {</a>
<a class="sourceLine" id="cb26-38" title="38">                Log.<span class="fu">d</span>(TAG, <span class="st">&quot;onAdClicked&quot;</span>);</a>
<a class="sourceLine" id="cb26-39" title="39">                <span class="fu">showToast</span>(<span class="st">&quot;开屏广告点击&quot;</span>);</a>
<a class="sourceLine" id="cb26-40" title="40">            }</a>
<a class="sourceLine" id="cb26-41" title="41"></a>
<a class="sourceLine" id="cb26-42" title="42">            <span class="at">@Override</span></a>
<a class="sourceLine" id="cb26-43" title="43">            <span class="kw">public</span> <span class="dt">void</span> <span class="fu">onAdShow</span>(<span class="bu">View</span> view, <span class="dt">int</span> type) {</a>
<a class="sourceLine" id="cb26-44" title="44">                Log.<span class="fu">d</span>(TAG, <span class="st">&quot;onAdShow&quot;</span>);</a>
<a class="sourceLine" id="cb26-45" title="45">                <span class="fu">showToast</span>(<span class="st">&quot;开屏广告展示&quot;</span>);</a>
<a class="sourceLine" id="cb26-46" title="46">            }</a>
<a class="sourceLine" id="cb26-47" title="47"></a>
<a class="sourceLine" id="cb26-48" title="48">            <span class="at">@Override</span></a>
<a class="sourceLine" id="cb26-49" title="49">            <span class="kw">public</span> <span class="dt">void</span> <span class="fu">onAdSkip</span>() {</a>
<a class="sourceLine" id="cb26-50" title="50">                Log.<span class="fu">d</span>(TAG, <span class="st">&quot;onAdSkip&quot;</span>);</a>
<a class="sourceLine" id="cb26-51" title="51">                <span class="fu">showToast</span>(<span class="st">&quot;开屏广告跳过&quot;</span>);</a>
<a class="sourceLine" id="cb26-52" title="52">                <span class="fu">goToMainActivity</span>();</a>
<a class="sourceLine" id="cb26-53" title="53"></a>
<a class="sourceLine" id="cb26-54" title="54">            }</a>
<a class="sourceLine" id="cb26-55" title="55"></a>
<a class="sourceLine" id="cb26-56" title="56">            <span class="at">@Override</span></a>
<a class="sourceLine" id="cb26-57" title="57">            <span class="kw">public</span> <span class="dt">void</span> <span class="fu">onAdTimeOver</span>() {</a>
<a class="sourceLine" id="cb26-58" title="58">                Log.<span class="fu">d</span>(TAG, <span class="st">&quot;onAdTimeOver&quot;</span>);</a>
<a class="sourceLine" id="cb26-59" title="59">                <span class="fu">showToast</span>(<span class="st">&quot;开屏广告倒计时结束&quot;</span>);</a>
<a class="sourceLine" id="cb26-60" title="60">                <span class="fu">goToMainActivity</span>();</a>
<a class="sourceLine" id="cb26-61" title="61">            }</a>
<a class="sourceLine" id="cb26-62" title="62">        });</a>
<a class="sourceLine" id="cb26-63" title="63">    }</a>
<a class="sourceLine" id="cb26-64" title="64">}, AD_TIME_OUT);</a></code></pre></div>
<p>加载开屏广告具体示例详见Demo中的SplashActivity。</p>
<h3 id="接入插屏广告ttinteractionad">2.7 接入插屏广告（TTInteractionAd）</h3>
<p>本SDK为接入方提供插屏广告，该广告的效果为在activity之上弹出一个dialog。使用场景包括但不限于： 1、进入时展开：用户进入app首页或者用户进入详情页，弹出插屏广告； 2、滑到底部展开：用户在详情页浏览，浏览到最底部，弹出插屏广告； 3、回滑时展开：用户滑动返回上一页面，弹出插屏广告；</p>
<p>插屏广告支持的广告尺寸： 1:1, 3:2, 2:3 ，在请求传参过程中，需要按照比例的实际尺寸请求，比如1：1的尺寸，可以请求600x600。</p>
<h4 id="ttinteractionad接口说明">2.7.1 TTInteractionAd接口说明：</h4>
<div class="sourceCode" id="cb27"><pre class="sourceCode java"><code class="sourceCode java"><a class="sourceLine" id="cb27-1" title="1"><span class="kw">public</span> <span class="kw">interface</span> TTInteractionAd {</a>
<a class="sourceLine" id="cb27-2" title="2">    <span class="co">/**</span></a>
<a class="sourceLine" id="cb27-3" title="3">     <span class="co">*</span> 注册插屏广告交互回调</a>
<a class="sourceLine" id="cb27-4" title="4">     <span class="co">*</span></a>
<a class="sourceLine" id="cb27-5" title="5">     <span class="co">* </span><span class="an">@param listener </span>交互监听器</a>
<a class="sourceLine" id="cb27-6" title="6">     <span class="co">*/</span></a>
<a class="sourceLine" id="cb27-7" title="7">    <span class="dt">void</span> <span class="fu">setAdInteractionListener</span>(AdInteractionListener listener);</a>
<a class="sourceLine" id="cb27-8" title="8"></a>
<a class="sourceLine" id="cb27-9" title="9">    <span class="co">/**</span></a>
<a class="sourceLine" id="cb27-10" title="10">     <span class="co">*</span> 注册插屏广告的下载回调</a>
<a class="sourceLine" id="cb27-11" title="11">     <span class="co">*</span></a>
<a class="sourceLine" id="cb27-12" title="12">     <span class="co">* </span><span class="an">@param listener </span>下载状态回调</a>
<a class="sourceLine" id="cb27-13" title="13">     <span class="co">*/</span></a>
<a class="sourceLine" id="cb27-14" title="14">    <span class="dt">void</span> <span class="fu">setDownloadListener</span>(TTAppDownloadListener listener);</a>
<a class="sourceLine" id="cb27-15" title="15"></a>
<a class="sourceLine" id="cb27-16" title="16">    <span class="co">/**</span></a>
<a class="sourceLine" id="cb27-17" title="17">     <span class="co">*</span> 得到插屏广告的交互类型</a>
<a class="sourceLine" id="cb27-18" title="18">     <span class="co">*</span></a>
<a class="sourceLine" id="cb27-19" title="19">     <span class="co">* </span><span class="an">@return </span><span class="co">2在</span>浏览器内打开 （普通类型）3落地页（普通类型），<span class="co">4:</span>应用下载，5:拨打电话 <span class="co">-1</span> 未知类型</a>
<a class="sourceLine" id="cb27-20" title="20">     <span class="co">*/</span></a>
<a class="sourceLine" id="cb27-21" title="21">    <span class="dt">int</span> <span class="fu">getInteractionType</span>();</a>
<a class="sourceLine" id="cb27-22" title="22"></a>
<a class="sourceLine" id="cb27-23" title="23">    <span class="co">/**</span></a>
<a class="sourceLine" id="cb27-24" title="24">     <span class="co">* </span><span class="an">@param activity </span>宿主activity<span class="co">,</span>用户判断宿主是否finishing</a>
<a class="sourceLine" id="cb27-25" title="25">     <span class="co">*/</span></a>
<a class="sourceLine" id="cb27-26" title="26">    <span class="at">@MainThread</span></a>
<a class="sourceLine" id="cb27-27" title="27">    <span class="dt">void</span> <span class="fu">showInteractionAd</span>(Activity activity);</a>
<a class="sourceLine" id="cb27-28" title="28"></a>
<a class="sourceLine" id="cb27-29" title="29">    <span class="co">/**</span></a>
<a class="sourceLine" id="cb27-30" title="30">     <span class="co">*</span> 插屏广告交互监听器</a>
<a class="sourceLine" id="cb27-31" title="31">     <span class="co">*/</span></a>
<a class="sourceLine" id="cb27-32" title="32">    <span class="kw">interface</span> AdInteractionListener {</a>
<a class="sourceLine" id="cb27-33" title="33"></a>
<a class="sourceLine" id="cb27-34" title="34">        <span class="co">/**</span></a>
<a class="sourceLine" id="cb27-35" title="35">         <span class="co">*</span> 插屏广告的点击回调</a>
<a class="sourceLine" id="cb27-36" title="36">         <span class="co">*/</span></a>
<a class="sourceLine" id="cb27-37" title="37">        <span class="dt">void</span> <span class="fu">onAdClicked</span>();</a>
<a class="sourceLine" id="cb27-38" title="38"></a>
<a class="sourceLine" id="cb27-39" title="39">        <span class="co">/**</span></a>
<a class="sourceLine" id="cb27-40" title="40">         <span class="co">*</span> 插屏广告的展示回调 每个广告仅回调一次</a>
<a class="sourceLine" id="cb27-41" title="41">         <span class="co">*/</span></a>
<a class="sourceLine" id="cb27-42" title="42">        <span class="dt">void</span> <span class="fu">onAdShow</span>();</a>
<a class="sourceLine" id="cb27-43" title="43"></a>
<a class="sourceLine" id="cb27-44" title="44">        <span class="co">/**</span></a>
<a class="sourceLine" id="cb27-45" title="45">         <span class="co">*</span> 插屏广告消失用户回调</a>
<a class="sourceLine" id="cb27-46" title="46">         <span class="co">*/</span></a>
<a class="sourceLine" id="cb27-47" title="47">        <span class="dt">void</span> <span class="fu">onAdDismiss</span>();</a>
<a class="sourceLine" id="cb27-48" title="48">    }</a>
<a class="sourceLine" id="cb27-49" title="49">}</a></code></pre></div>
<h4 id="加载插屏广告">2.7.2 加载插屏广告</h4>
<p>接入方可调用TTAdNative.loadInteractionAd(AdSlot adSlot, <span class="citation" data-cites="NonNull">@NonNull</span> InteractionAdListener listener)异步加载插屏广告，adslot为请求广告的信息，InteractionAdListener为广告加载成功或失败的回调。具体示例如下：</p>
<div class="sourceCode" id="cb28"><pre class="sourceCode java"><code class="sourceCode java"><a class="sourceLine" id="cb28-1" title="1"> mTTAdNative.<span class="fu">loadInteractionAd</span>(adSlot, <span class="kw">new</span> TTAdNative.<span class="fu">InteractionAdListener</span>() {</a>
<a class="sourceLine" id="cb28-2" title="2">    <span class="at">@Override</span></a>
<a class="sourceLine" id="cb28-3" title="3">    <span class="kw">public</span> <span class="dt">void</span> <span class="fu">onError</span>(<span class="dt">int</span> code, <span class="bu">String</span> message) {</a>
<a class="sourceLine" id="cb28-4" title="4">        Toast.<span class="fu">makeText</span>(<span class="fu">getApplicationContext</span>(), <span class="st">&quot;code: &quot;</span> + code + <span class="st">&quot;  message: &quot;</span> + message, Toast.<span class="fu">LENGTH_SHORT</span>).<span class="fu">show</span>();</a>
<a class="sourceLine" id="cb28-5" title="5">    }</a>
<a class="sourceLine" id="cb28-6" title="6"></a>
<a class="sourceLine" id="cb28-7" title="7">    <span class="at">@Override</span></a>
<a class="sourceLine" id="cb28-8" title="8">    <span class="kw">public</span> <span class="dt">void</span> <span class="fu">onInteractionAdLoad</span>(TTInteractionAd ttInteractionAd) {</a>
<a class="sourceLine" id="cb28-9" title="9">        Toast.<span class="fu">makeText</span>(<span class="fu">getApplicationContext</span>(), <span class="st">&quot;type:  &quot;</span> + ttInteractionAd.<span class="fu">getInteractionType</span>(), Toast.<span class="fu">LENGTH_SHORT</span>).<span class="fu">show</span>();</a>
<a class="sourceLine" id="cb28-10" title="10">        ttInteractionAd.<span class="fu">setAdInteractionListener</span>(<span class="kw">new</span> TTInteractionAd.<span class="fu">AdInteractionListener</span>() {</a>
<a class="sourceLine" id="cb28-11" title="11">            <span class="at">@Override</span></a>
<a class="sourceLine" id="cb28-12" title="12">            <span class="kw">public</span> <span class="dt">void</span> <span class="fu">onAdClicked</span>() {</a>
<a class="sourceLine" id="cb28-13" title="13">                Log.<span class="fu">d</span>(TAG, <span class="st">&quot;被点击&quot;</span>);</a>
<a class="sourceLine" id="cb28-14" title="14">                Toast.<span class="fu">makeText</span>(mContext, <span class="st">&quot;广告被点击&quot;</span>, Toast.<span class="fu">LENGTH_SHORT</span>).<span class="fu">show</span>();</a>
<a class="sourceLine" id="cb28-15" title="15">            }</a>
<a class="sourceLine" id="cb28-16" title="16"></a>
<a class="sourceLine" id="cb28-17" title="17">            <span class="at">@Override</span></a>
<a class="sourceLine" id="cb28-18" title="18">            <span class="kw">public</span> <span class="dt">void</span> <span class="fu">onAdShow</span>() {</a>
<a class="sourceLine" id="cb28-19" title="19">                Log.<span class="fu">d</span>(TAG, <span class="st">&quot;被展示&quot;</span>);</a>
<a class="sourceLine" id="cb28-20" title="20">                Toast.<span class="fu">makeText</span>(mContext, <span class="st">&quot;广告被展示&quot;</span>, Toast.<span class="fu">LENGTH_SHORT</span>).<span class="fu">show</span>();</a>
<a class="sourceLine" id="cb28-21" title="21">            }</a>
<a class="sourceLine" id="cb28-22" title="22"></a>
<a class="sourceLine" id="cb28-23" title="23">            <span class="at">@Override</span></a>
<a class="sourceLine" id="cb28-24" title="24">            <span class="kw">public</span> <span class="dt">void</span> <span class="fu">onAdDismiss</span>() {</a>
<a class="sourceLine" id="cb28-25" title="25">                Log.<span class="fu">d</span>(TAG, <span class="st">&quot;插屏广告消失&quot;</span>);</a>
<a class="sourceLine" id="cb28-26" title="26">                Toast.<span class="fu">makeText</span>(mContext, <span class="st">&quot;广告消失&quot;</span>, Toast.<span class="fu">LENGTH_SHORT</span>).<span class="fu">show</span>();</a>
<a class="sourceLine" id="cb28-27" title="27">            }</a>
<a class="sourceLine" id="cb28-28" title="28">        });</a>
<a class="sourceLine" id="cb28-29" title="29">        <span class="co">//如果是下载类型的广告，可以注册下载状态回调监听</span></a>
<a class="sourceLine" id="cb28-30" title="30">        <span class="kw">if</span> (ttInteractionAd.<span class="fu">getInteractionType</span>() == TTAdConstant.<span class="fu">INTERACTION_TYPE_DOWNLOAD</span>) {</a>
<a class="sourceLine" id="cb28-31" title="31">            ttInteractionAd.<span class="fu">setDownloadListener</span>(<span class="kw">new</span> <span class="fu">TTAppDownloadListener</span>() {</a>
<a class="sourceLine" id="cb28-32" title="32">                <span class="at">@Override</span></a>
<a class="sourceLine" id="cb28-33" title="33">                <span class="kw">public</span> <span class="dt">void</span> <span class="fu">onIdle</span>() {</a>
<a class="sourceLine" id="cb28-34" title="34">                    Log.<span class="fu">d</span>(TAG, <span class="st">&quot;点击开始下载&quot;</span>);</a>
<a class="sourceLine" id="cb28-35" title="35">                    Toast.<span class="fu">makeText</span>(mContext, <span class="st">&quot;点击开始下载&quot;</span>, Toast.<span class="fu">LENGTH_SHORT</span>).<span class="fu">show</span>();</a>
<a class="sourceLine" id="cb28-36" title="36">                }</a>
<a class="sourceLine" id="cb28-37" title="37"></a>
<a class="sourceLine" id="cb28-38" title="38">                <span class="at">@Override</span></a>
<a class="sourceLine" id="cb28-39" title="39">                <span class="kw">public</span> <span class="dt">void</span> <span class="fu">onDownloadActive</span>(<span class="dt">long</span> totalBytes, <span class="dt">long</span> currBytes, <span class="bu">String</span> fileName) {</a>
<a class="sourceLine" id="cb28-40" title="40">                    Log.<span class="fu">d</span>(TAG, <span class="st">&quot;下载中&quot;</span>);</a>
<a class="sourceLine" id="cb28-41" title="41">                    Toast.<span class="fu">makeText</span>(mContext, <span class="st">&quot;下载中&quot;</span>, Toast.<span class="fu">LENGTH_SHORT</span>).<span class="fu">show</span>();</a>
<a class="sourceLine" id="cb28-42" title="42">                }</a>
<a class="sourceLine" id="cb28-43" title="43"></a>
<a class="sourceLine" id="cb28-44" title="44">                <span class="at">@Override</span></a>
<a class="sourceLine" id="cb28-45" title="45">                <span class="kw">public</span> <span class="dt">void</span> <span class="fu">onDownloadPaused</span>(<span class="dt">long</span> totalBytes, <span class="dt">long</span> currBytes, <span class="bu">String</span> fileName) {</a>
<a class="sourceLine" id="cb28-46" title="46">                    Log.<span class="fu">d</span>(TAG, <span class="st">&quot;下载暂停&quot;</span>);</a>
<a class="sourceLine" id="cb28-47" title="47">                    Toast.<span class="fu">makeText</span>(mContext, <span class="st">&quot;下载暂停&quot;</span>, Toast.<span class="fu">LENGTH_SHORT</span>).<span class="fu">show</span>();</a>
<a class="sourceLine" id="cb28-48" title="48">                }</a>
<a class="sourceLine" id="cb28-49" title="49"></a>
<a class="sourceLine" id="cb28-50" title="50">                <span class="at">@Override</span></a>
<a class="sourceLine" id="cb28-51" title="51">                <span class="kw">public</span> <span class="dt">void</span> <span class="fu">onDownloadFailed</span>(<span class="dt">long</span> totalBytes, <span class="dt">long</span> currBytes, <span class="bu">String</span> fileName) {</a>
<a class="sourceLine" id="cb28-52" title="52">                    Log.<span class="fu">d</span>(TAG, <span class="st">&quot;下载失败&quot;</span>);</a>
<a class="sourceLine" id="cb28-53" title="53">                    Toast.<span class="fu">makeText</span>(mContext, <span class="st">&quot;下载失败&quot;</span>, Toast.<span class="fu">LENGTH_SHORT</span>).<span class="fu">show</span>();</a>
<a class="sourceLine" id="cb28-54" title="54">                }</a>
<a class="sourceLine" id="cb28-55" title="55"></a>
<a class="sourceLine" id="cb28-56" title="56">                <span class="at">@Override</span></a>
<a class="sourceLine" id="cb28-57" title="57">                <span class="kw">public</span> <span class="dt">void</span> <span class="fu">onDownloadFinished</span>(<span class="dt">long</span> totalBytes, <span class="bu">String</span> fileName) {</a>
<a class="sourceLine" id="cb28-58" title="58">                    Log.<span class="fu">d</span>(TAG, <span class="st">&quot;下载完成&quot;</span>);</a>
<a class="sourceLine" id="cb28-59" title="59">                    Toast.<span class="fu">makeText</span>(mContext, <span class="st">&quot;下载完成&quot;</span>, Toast.<span class="fu">LENGTH_SHORT</span>).<span class="fu">show</span>();</a>
<a class="sourceLine" id="cb28-60" title="60">                }</a>
<a class="sourceLine" id="cb28-61" title="61"></a>
<a class="sourceLine" id="cb28-62" title="62">                <span class="at">@Override</span></a>
<a class="sourceLine" id="cb28-63" title="63">                <span class="kw">public</span> <span class="dt">void</span> <span class="fu">onInstalled</span>(<span class="bu">String</span> fileName) {</a>
<a class="sourceLine" id="cb28-64" title="64">                    Log.<span class="fu">d</span>(TAG, <span class="st">&quot;安装完成&quot;</span>);</a>
<a class="sourceLine" id="cb28-65" title="65">                    Toast.<span class="fu">makeText</span>(mContext, <span class="st">&quot;安装完成&quot;</span>, Toast.<span class="fu">LENGTH_SHORT</span>).<span class="fu">show</span>();</a>
<a class="sourceLine" id="cb28-66" title="66">                }</a>
<a class="sourceLine" id="cb28-67" title="67">            });</a>
<a class="sourceLine" id="cb28-68" title="68">        }</a>
<a class="sourceLine" id="cb28-69" title="69">        <span class="co">//弹出插屏广告</span></a>
<a class="sourceLine" id="cb28-70" title="70">        ttInteractionAd.<span class="fu">showInteractionAd</span>(InteractionActivity.<span class="fu">this</span>);</a>
<a class="sourceLine" id="cb28-71" title="71">    }</a>
<a class="sourceLine" id="cb28-72" title="72">});</a></code></pre></div>
<h4 id="展示插屏广告">2.7.3 展示插屏广告</h4>
<p>在加载到插屏广告成功后，请调用ttInteractionAd.showInteractionAd()方法展示广告。 <strong>注意：请在主线程中调用showInteractionAd()</strong></p>
<div class="sourceCode" id="cb29"><pre class="sourceCode java"><code class="sourceCode java"><a class="sourceLine" id="cb29-1" title="1"><span class="co">//弹出插屏广告</span></a>
<a class="sourceLine" id="cb29-2" title="2">ttInteractionAd.<span class="fu">showInteractionAd</span>(InteractionActivity.<span class="fu">this</span>);</a></code></pre></div>
<p>加载及展示插屏广告具体示例详见Demo中的InteractionActivity。</p>
<h3 id="接入原生广告ttnativead">2.8 接入原生广告（TTNativeAd）</h3>
<p>本SDK为接入方提供原生广告，目前支持原生广告自渲染横幅和插屏两种广告，接入方式与TTFeedAd接入基本一致。</p>
<h4 id="ttnativead接口说明">2.8.1 TTNativeAd接口说明：</h4>
<div class="sourceCode" id="cb30"><pre class="sourceCode java"><code class="sourceCode java"><a class="sourceLine" id="cb30-1" title="1"><span class="kw">public</span> <span class="kw">interface</span> TTNativeAd {</a>
<a class="sourceLine" id="cb30-2" title="2"></a>
<a class="sourceLine" id="cb30-3" title="3">    <span class="co">/**</span></a>
<a class="sourceLine" id="cb30-4" title="4">     <span class="co">*</span> 获取穿山甲穿山甲logo，图片大小：8<span class="co">0*80</span></a>
<a class="sourceLine" id="cb30-5" title="5">     <span class="co">*</span></a>
<a class="sourceLine" id="cb30-6" title="6">     <span class="co">* </span><span class="an">@return </span>bitmap对象</a>
<a class="sourceLine" id="cb30-7" title="7">     <span class="co">*/</span></a>
<a class="sourceLine" id="cb30-8" title="8">    Bitmap <span class="fu">getAdLogo</span>();</a>
<a class="sourceLine" id="cb30-9" title="9"></a>
<a class="sourceLine" id="cb30-10" title="10">    <span class="co">/**</span></a>
<a class="sourceLine" id="cb30-11" title="11">     <span class="co">*</span> 广告标题</a>
<a class="sourceLine" id="cb30-12" title="12">     <span class="co">*</span></a>
<a class="sourceLine" id="cb30-13" title="13">     <span class="co">* @</span>return</a>
<a class="sourceLine" id="cb30-14" title="14">     <span class="co">*/</span></a>
<a class="sourceLine" id="cb30-15" title="15">    <span class="bu">String</span> <span class="fu">getTitle</span>();</a>
<a class="sourceLine" id="cb30-16" title="16"></a>
<a class="sourceLine" id="cb30-17" title="17">    <span class="co">/**</span></a>
<a class="sourceLine" id="cb30-18" title="18">     <span class="co">*</span> 广告描述</a>
<a class="sourceLine" id="cb30-19" title="19">     <span class="co">*</span></a>
<a class="sourceLine" id="cb30-20" title="20">     <span class="co">* @</span>return</a>
<a class="sourceLine" id="cb30-21" title="21">     <span class="co">*/</span></a>
<a class="sourceLine" id="cb30-22" title="22">    <span class="bu">String</span> <span class="fu">getDescription</span>();</a>
<a class="sourceLine" id="cb30-23" title="23"></a>
<a class="sourceLine" id="cb30-24" title="24">    <span class="co">/**</span></a>
<a class="sourceLine" id="cb30-25" title="25">     <span class="co">*</span> 广告来源</a>
<a class="sourceLine" id="cb30-26" title="26">     <span class="co">*</span></a>
<a class="sourceLine" id="cb30-27" title="27">     <span class="co">* @</span>return</a>
<a class="sourceLine" id="cb30-28" title="28">     <span class="co">*/</span></a>
<a class="sourceLine" id="cb30-29" title="29">    <span class="bu">String</span> <span class="fu">getSource</span>();</a>
<a class="sourceLine" id="cb30-30" title="30"></a>
<a class="sourceLine" id="cb30-31" title="31">    <span class="co">/**</span></a>
<a class="sourceLine" id="cb30-32" title="32">     <span class="co">*</span> 广告图标Image</a>
<a class="sourceLine" id="cb30-33" title="33">     <span class="co">*</span></a>
<a class="sourceLine" id="cb30-34" title="34">     <span class="co">* @</span>return</a>
<a class="sourceLine" id="cb30-35" title="35">     <span class="co">*/</span></a>
<a class="sourceLine" id="cb30-36" title="36">    TTImage <span class="fu">getIcon</span>();</a>
<a class="sourceLine" id="cb30-37" title="37"></a>
<a class="sourceLine" id="cb30-38" title="38">    <span class="co">/**</span></a>
<a class="sourceLine" id="cb30-39" title="39">     <span class="co">*</span> 广告图片Image list</a>
<a class="sourceLine" id="cb30-40" title="40">     <span class="co">*</span></a>
<a class="sourceLine" id="cb30-41" title="41">     <span class="co">* @</span>return</a>
<a class="sourceLine" id="cb30-42" title="42">     <span class="co">*/</span></a>
<a class="sourceLine" id="cb30-43" title="43">    <span class="bu">List</span>&lt;TTImage&gt; <span class="fu">getImageList</span>();</a>
<a class="sourceLine" id="cb30-44" title="44"></a>
<a class="sourceLine" id="cb30-45" title="45">    <span class="co">/**</span></a>
<a class="sourceLine" id="cb30-46" title="46">     <span class="co">*</span> 获取原生广告交互类型</a>
<a class="sourceLine" id="cb30-47" title="47">     <span class="co">*</span></a>
<a class="sourceLine" id="cb30-48" title="48">     <span class="co">* </span><span class="an">@return </span><span class="co">2:</span>在浏览器打开网页，3<span class="co">:</span>在app中打开，<span class="co">4:</span>下载应用，5<span class="co">:</span>拨打电话 其它：未知类型</a>
<a class="sourceLine" id="cb30-49" title="49">     <span class="co">*/</span></a>
<a class="sourceLine" id="cb30-50" title="50">    <span class="dt">int</span> <span class="fu">getInteractionType</span>();</a>
<a class="sourceLine" id="cb30-51" title="51"></a>
<a class="sourceLine" id="cb30-52" title="52"></a>
<a class="sourceLine" id="cb30-53" title="53">    <span class="co">/**</span></a>
<a class="sourceLine" id="cb30-54" title="54">     <span class="co">*</span> 得到原生广告图片模式</a>
<a class="sourceLine" id="cb30-55" title="55">     <span class="co">*</span></a>
<a class="sourceLine" id="cb30-56" title="56">     <span class="co">* </span><span class="an">@return </span><span class="co">3</span> 大图 <span class="co">2小</span>图 <span class="co">4</span> 组图 <span class="co">5</span> 视频 其它：未知类型</a>
<a class="sourceLine" id="cb30-57" title="57">     <span class="co">*/</span></a>
<a class="sourceLine" id="cb30-58" title="58">    <span class="dt">int</span> <span class="fu">getImageMode</span>();</a>
<a class="sourceLine" id="cb30-59" title="59"></a>
<a class="sourceLine" id="cb30-60" title="60">    <span class="co">/**</span></a>
<a class="sourceLine" id="cb30-61" title="61">     <span class="co">*</span> 得到dislike dialog</a>
<a class="sourceLine" id="cb30-62" title="62">     <span class="co">*</span></a>
<a class="sourceLine" id="cb30-63" title="63">     <span class="co">* </span><span class="an">@param activity </span>建议传当前activity，否则可能会影响dislike对话框弹出</a>
<a class="sourceLine" id="cb30-64" title="64">     <span class="co">*</span> <span class="co">@</span>return</a>
<a class="sourceLine" id="cb30-65" title="65">     <span class="co">*/</span></a>
<a class="sourceLine" id="cb30-66" title="66">    TTAdDislike <span class="fu">getDislikeDialog</span>(Activity activity);</a>
<a class="sourceLine" id="cb30-67" title="67"></a>
<a class="sourceLine" id="cb30-68" title="68">    <span class="co">/**</span></a>
<a class="sourceLine" id="cb30-69" title="69">     <span class="co">*</span> 自定义dislike dialog</a>
<a class="sourceLine" id="cb30-70" title="70">     <span class="co">*</span></a>
<a class="sourceLine" id="cb30-71" title="71">     <span class="co">* </span><span class="an">@param dialog </span>自定义dialog，需要由外部传入</a>
<a class="sourceLine" id="cb30-72" title="72">     <span class="co">*</span> <span class="co">@</span>return</a>
<a class="sourceLine" id="cb30-73" title="73">     <span class="co">*/</span></a>
<a class="sourceLine" id="cb30-74" title="74">    TTAdDislike <span class="fu">getDislikeDialog</span>(TTDislikeDialogAbstract dialog);</a>
<a class="sourceLine" id="cb30-75" title="75"></a>
<a class="sourceLine" id="cb30-76" title="76">    <span class="co">/**</span></a>
<a class="sourceLine" id="cb30-77" title="77">     <span class="co">*</span> 获取下载状态控制器</a>
<a class="sourceLine" id="cb30-78" title="78">     <span class="co">*/</span></a>
<a class="sourceLine" id="cb30-79" title="79">    DownloadStatusController <span class="fu">getDownloadStatusController</span>();</a>
<a class="sourceLine" id="cb30-80" title="80"></a>
<a class="sourceLine" id="cb30-81" title="81">    <span class="co">/**</span></a>
<a class="sourceLine" id="cb30-82" title="82">     <span class="co">*</span> 注册可点击的View，click<span class="co">/</span>show会在内部完成</a>
<a class="sourceLine" id="cb30-83" title="83">     <span class="co">*</span></a>
<a class="sourceLine" id="cb30-84" title="84">     <span class="co">* </span><span class="an">@param container </span>渲染广告最外层的ViewGroup</a>
<a class="sourceLine" id="cb30-85" title="85">     <span class="co">*</span> <span class="an">@param clickView </span>可点击的View</a>
<a class="sourceLine" id="cb30-86" title="86">     <span class="co">*/</span></a>
<a class="sourceLine" id="cb30-87" title="87">    <span class="dt">void</span> <span class="fu">registerViewForInteraction</span>(<span class="at">@NonNull</span> ViewGroup container, <span class="at">@NonNull</span> <span class="bu">View</span> clickView, AdInteractionListener listener);</a>
<a class="sourceLine" id="cb30-88" title="88"></a>
<a class="sourceLine" id="cb30-89" title="89">    <span class="co">/**</span></a>
<a class="sourceLine" id="cb30-90" title="90">     <span class="co">*</span> 注册可点击的View，click<span class="co">/</span>show会在内部完成</a>
<a class="sourceLine" id="cb30-91" title="91">     <span class="co">*</span></a>
<a class="sourceLine" id="cb30-92" title="92">     <span class="co">* </span><span class="an">@param container </span>    渲染广告最外层的ViewGroup</a>
<a class="sourceLine" id="cb30-93" title="93">     <span class="co">*</span> <span class="an">@param clickViews </span>   可点击的View的列表</a>
<a class="sourceLine" id="cb30-94" title="94">     <span class="co">*</span> <span class="an">@param creativeViews </span>用于下载或者拨打电话的View</a>
<a class="sourceLine" id="cb30-95" title="95">     <span class="co">*/</span></a>
<a class="sourceLine" id="cb30-96" title="96">    <span class="dt">void</span> <span class="fu">registerViewForInteraction</span>(<span class="at">@NonNull</span> ViewGroup container, <span class="at">@NonNull</span> <span class="bu">List</span>&lt;<span class="bu">View</span>&gt; clickViews, <span class="at">@Nullable</span> <span class="bu">List</span>&lt;<span class="bu">View</span>&gt; creativeViews, AdInteractionListener listener);</a>
<a class="sourceLine" id="cb30-97" title="97"></a>
<a class="sourceLine" id="cb30-98" title="98">    <span class="co">/**</span></a>
<a class="sourceLine" id="cb30-99" title="99">     <span class="co">*</span> 注册可点击的View，click<span class="co">/</span>show会在内部完成，注册dislike按钮</a>
<a class="sourceLine" id="cb30-100" title="100">     <span class="co">*</span></a>
<a class="sourceLine" id="cb30-101" title="101">     <span class="co">* </span><span class="an">@param container </span>    渲染广告最外层的ViewGroup</a>
<a class="sourceLine" id="cb30-102" title="102">     <span class="co">*</span> <span class="an">@param clickViews </span>   可点击的View的列表</a>
<a class="sourceLine" id="cb30-103" title="103">     <span class="co">*</span> <span class="an">@param creativeViews </span>用于下载或者拨打电话的View</a>
<a class="sourceLine" id="cb30-104" title="104">     <span class="co">*</span> <span class="an">@param dislikeView </span>  dislike按钮</a>
<a class="sourceLine" id="cb30-105" title="105">     <span class="co">*</span> <span class="an">@param listener </span>     点击回调</a>
<a class="sourceLine" id="cb30-106" title="106">     <span class="co">*/</span></a>
<a class="sourceLine" id="cb30-107" title="107">    <span class="dt">void</span> <span class="fu">registerViewForInteraction</span>(<span class="at">@NonNull</span> ViewGroup container, <span class="at">@NonNull</span> <span class="bu">List</span>&lt;<span class="bu">View</span>&gt; clickViews, <span class="at">@Nullable</span> <span class="bu">List</span>&lt;<span class="bu">View</span>&gt; creativeViews, <span class="at">@Nullable</span> <span class="bu">View</span> dislikeView, AdInteractionListener listener);</a>
<a class="sourceLine" id="cb30-108" title="108"></a>
<a class="sourceLine" id="cb30-109" title="109">    <span class="co">/**</span></a>
<a class="sourceLine" id="cb30-110" title="110">     <span class="co">*</span> 设置下载监听器</a>
<a class="sourceLine" id="cb30-111" title="111">     <span class="co">*/</span></a>
<a class="sourceLine" id="cb30-112" title="112">    <span class="dt">void</span> <span class="fu">setDownloadListener</span>(TTAppDownloadListener downloadListener);</a>
<a class="sourceLine" id="cb30-113" title="113"></a>
<a class="sourceLine" id="cb30-114" title="114">    <span class="co">/**</span></a>
<a class="sourceLine" id="cb30-115" title="115">     <span class="co">*</span> 兼容下载类广告，使用activity申请权限</a>
<a class="sourceLine" id="cb30-116" title="116">     <span class="co">*/</span></a>
<a class="sourceLine" id="cb30-117" title="117">    <span class="dt">void</span> <span class="fu">setActivityForDownloadApp</span>(<span class="at">@NonNull</span> Activity activity);</a>
<a class="sourceLine" id="cb30-118" title="118"></a>
<a class="sourceLine" id="cb30-119" title="119">    <span class="bu">View</span> <span class="fu">getAdView</span>();</a>
<a class="sourceLine" id="cb30-120" title="120"></a>
<a class="sourceLine" id="cb30-121" title="121">    <span class="co">/**</span></a>
<a class="sourceLine" id="cb30-122" title="122">     <span class="co">*</span> 信息流广告交互回调接口</a>
<a class="sourceLine" id="cb30-123" title="123">     <span class="co">*/</span></a>
<a class="sourceLine" id="cb30-124" title="124">    <span class="kw">interface</span> AdInteractionListener {</a>
<a class="sourceLine" id="cb30-125" title="125"></a>
<a class="sourceLine" id="cb30-126" title="126">        <span class="co">/**</span></a>
<a class="sourceLine" id="cb30-127" title="127">         <span class="co">*</span> 广告点击的回调，点击后的动作由sdk控制</a>
<a class="sourceLine" id="cb30-128" title="128">         <span class="co">*</span></a>
<a class="sourceLine" id="cb30-129" title="129">         <span class="co">* </span><span class="an">@param ad</span></a>
<a class="sourceLine" id="cb30-130" title="130">         <span class="co">*/</span></a>
<a class="sourceLine" id="cb30-131" title="131">        <span class="dt">void</span> <span class="fu">onAdClicked</span>(<span class="bu">View</span> view, TTNativeAd ad);</a>
<a class="sourceLine" id="cb30-132" title="132"></a>
<a class="sourceLine" id="cb30-133" title="133">        <span class="co">/**</span></a>
<a class="sourceLine" id="cb30-134" title="134">         <span class="co">*</span> 创意广告点击回调</a>
<a class="sourceLine" id="cb30-135" title="135">         <span class="co">*</span></a>
<a class="sourceLine" id="cb30-136" title="136">         <span class="co">* </span><span class="an">@param view</span></a>
<a class="sourceLine" id="cb30-137" title="137">         <span class="co">*</span> <span class="an">@param ad</span></a>
<a class="sourceLine" id="cb30-138" title="138">         <span class="co">*/</span></a>
<a class="sourceLine" id="cb30-139" title="139">        <span class="dt">void</span> <span class="fu">onAdCreativeClick</span>(<span class="bu">View</span> view, TTNativeAd ad);</a>
<a class="sourceLine" id="cb30-140" title="140"></a>
<a class="sourceLine" id="cb30-141" title="141">        <span class="co">/**</span></a>
<a class="sourceLine" id="cb30-142" title="142">         <span class="co">*</span> 广告展示回调 每个广告仅回调一次</a>
<a class="sourceLine" id="cb30-143" title="143">         <span class="co">*</span></a>
<a class="sourceLine" id="cb30-144" title="144">         <span class="co">* </span><span class="an">@param ad</span></a>
<a class="sourceLine" id="cb30-145" title="145">         <span class="co">*/</span></a>
<a class="sourceLine" id="cb30-146" title="146">        <span class="dt">void</span> <span class="fu">onAdShow</span>(TTNativeAd ad);</a>
<a class="sourceLine" id="cb30-147" title="147">    }</a>
<a class="sourceLine" id="cb30-148" title="148">}</a></code></pre></div>
<h4 id="加载原生广告">2.8.2 加载原生广告</h4>
<p>接入方可调用<code>loadNativeAd(AdSlot adSlot, @NonNull NativeAdListener listener)</code>异步加载原生广告，adslot为请求广告的信息，NativeAdListener为广告加载成功或失败的回调。</p>
<div class="sourceCode" id="cb31"><pre class="sourceCode java"><code class="sourceCode java"><a class="sourceLine" id="cb31-1" title="1">   <span class="co">//step4:创建广告请求参数AdSlot,注意其中的setNativeAdtype方法，具体参数含义参考文档</span></a>
<a class="sourceLine" id="cb31-2" title="2">        <span class="dt">final</span> AdSlot adSlot = <span class="kw">new</span> AdSlot.<span class="fu">Builder</span>()</a>
<a class="sourceLine" id="cb31-3" title="3">                .<span class="fu">setCodeId</span>(codeId)</a>
<a class="sourceLine" id="cb31-4" title="4">                .<span class="fu">setSupportDeepLink</span>(<span class="kw">true</span>)</a>
<a class="sourceLine" id="cb31-5" title="5">                .<span class="fu">setImageAcceptedSize</span>(<span class="dv">600</span>, <span class="dv">257</span>)</a>
<a class="sourceLine" id="cb31-6" title="6">                .<span class="fu">setNativeAdType</span>(AdSlot.<span class="fu">TYPE_BANNER</span>) <span class="co">//请求原生广告时候，请务必调用该方法，设置参数为TYPE_BANNER或TYPE_INTERACTION_AD</span></a>
<a class="sourceLine" id="cb31-7" title="7">                .<span class="fu">setAdCount</span>(<span class="dv">1</span>)</a>
<a class="sourceLine" id="cb31-8" title="8">                .<span class="fu">build</span>();</a>
<a class="sourceLine" id="cb31-9" title="9"></a>
<a class="sourceLine" id="cb31-10" title="10">        <span class="co">//step5:请求广告，对请求回调的广告作渲染处理</span></a>
<a class="sourceLine" id="cb31-11" title="11">        mTTAdNative.<span class="fu">loadNativeAd</span>(adSlot, <span class="kw">new</span> TTAdNative.<span class="fu">NativeAdListener</span>() {</a>
<a class="sourceLine" id="cb31-12" title="12">            <span class="at">@Override</span></a>
<a class="sourceLine" id="cb31-13" title="13">            <span class="kw">public</span> <span class="dt">void</span> <span class="fu">onError</span>(<span class="dt">int</span> code, <span class="bu">String</span> message) {</a>
<a class="sourceLine" id="cb31-14" title="14">                TToast.<span class="fu">show</span>(NativeBannerActivity.<span class="fu">this</span>, <span class="st">&quot;load error : &quot;</span> + code + <span class="st">&quot;, &quot;</span> + message);</a>
<a class="sourceLine" id="cb31-15" title="15">            }</a>
<a class="sourceLine" id="cb31-16" title="16"></a>
<a class="sourceLine" id="cb31-17" title="17">            <span class="at">@Override</span></a>
<a class="sourceLine" id="cb31-18" title="18">            <span class="kw">public</span> <span class="dt">void</span> <span class="fu">onNativeAdLoad</span>(<span class="bu">List</span>&lt;TTNativeAd&gt; ads) {</a>
<a class="sourceLine" id="cb31-19" title="19">                <span class="kw">if</span> (ads.<span class="fu">get</span>(<span class="dv">0</span>) == <span class="kw">null</span>) {</a>
<a class="sourceLine" id="cb31-20" title="20">                    <span class="kw">return</span>;</a>
<a class="sourceLine" id="cb31-21" title="21">                }</a>
<a class="sourceLine" id="cb31-22" title="22">                <span class="bu">View</span> bannerView = LayoutInflater.<span class="fu">from</span>(mContext).<span class="fu">inflate</span>(R.<span class="fu">layout</span>.<span class="fu">native_ad</span>, mBannerContainer, <span class="kw">false</span>);</a>
<a class="sourceLine" id="cb31-23" title="23">                <span class="kw">if</span> (bannerView == <span class="kw">null</span>) {</a>
<a class="sourceLine" id="cb31-24" title="24">                    <span class="kw">return</span>;</a>
<a class="sourceLine" id="cb31-25" title="25">                }</a>
<a class="sourceLine" id="cb31-26" title="26">                mBannerContainer.<span class="fu">removeAllViews</span>();</a>
<a class="sourceLine" id="cb31-27" title="27">                mBannerContainer.<span class="fu">addView</span>(bannerView);</a>
<a class="sourceLine" id="cb31-28" title="28">                <span class="co">//绑定原生广告的数据，请见Demo中NativeBannerActivity示例。</span></a>
<a class="sourceLine" id="cb31-29" title="29">                <span class="fu">setAdData</span>(bannerView, ads.<span class="fu">get</span>(<span class="dv">0</span>));</a>
<a class="sourceLine" id="cb31-30" title="30">            }</a>
<a class="sourceLine" id="cb31-31" title="31">        });</a></code></pre></div>
<h4 id="展示原生广告">2.8.3 展示原生广告</h4>
<div class="sourceCode" id="cb32"><pre class="sourceCode java"><code class="sourceCode java"><a class="sourceLine" id="cb32-1" title="1"> mBannerContainer.<span class="fu">removeAllViews</span>();</a>
<a class="sourceLine" id="cb32-2" title="2"> mBannerContainer.<span class="fu">addView</span>(bannerView);</a></code></pre></div>
<p>详细代码请参考demo中的NativeBannerActivity。</p>
<h3 id="接入激励视频广告ttrewardvideoad">2.9 接入激励视频广告（TTRewardVideoAd）</h3>
<p>本SDK为接入方提供激励视频广告，该广告的效果为观看完毕视频广告，发放奖励给用户。使用场景包括但不限于： 1、游戏等应用内观看视频广告获得游戏内金币等：用户必须观看完整视频才能获取奖励； 2、积分类应用接入；</p>
<p>支持的广告尺寸： 全屏横屏播放和竖屏，默认横屏</p>
<h4 id="ttrewardvideoad接口说明">2.9.1 TTRewardVideoAd接口说明：</h4>
<div class="sourceCode" id="cb33"><pre class="sourceCode java"><code class="sourceCode java"><a class="sourceLine" id="cb33-1" title="1"><span class="kw">public</span> <span class="kw">interface</span> TTRewardVideoAd {</a>
<a class="sourceLine" id="cb33-2" title="2">    <span class="co">/**</span></a>
<a class="sourceLine" id="cb33-3" title="3">     <span class="co">*</span> 设置视频交互回调</a>
<a class="sourceLine" id="cb33-4" title="4">     <span class="co">*/</span></a>
<a class="sourceLine" id="cb33-5" title="5">    <span class="dt">void</span> <span class="fu">setRewardAdInteractionListener</span>(TTRewardVideoAd.<span class="fu">RewardAdInteractionListener</span> var1);</a>
<a class="sourceLine" id="cb33-6" title="6"></a>
<a class="sourceLine" id="cb33-7" title="7">    <span class="co">/**</span></a>
<a class="sourceLine" id="cb33-8" title="8">     <span class="co">*</span> 设置下载应用的下载状态回调</a>
<a class="sourceLine" id="cb33-9" title="9">     <span class="co">*/</span></a>
<a class="sourceLine" id="cb33-10" title="10">    <span class="dt">void</span> <span class="fu">setDownloadListener</span>(TTAppDownloadListener var1);</a>
<a class="sourceLine" id="cb33-11" title="11"></a>
<a class="sourceLine" id="cb33-12" title="12">    <span class="co">/**</span></a>
<a class="sourceLine" id="cb33-13" title="13">     <span class="co">*</span> 返回视频广告的交互类型，目前为下载类</a>
<a class="sourceLine" id="cb33-14" title="14">     <span class="co">*/</span></a>
<a class="sourceLine" id="cb33-15" title="15">    <span class="dt">int</span> <span class="fu">getInteractionType</span>();</a>
<a class="sourceLine" id="cb33-16" title="16"></a>
<a class="sourceLine" id="cb33-17" title="17">    <span class="co">/**</span></a>
<a class="sourceLine" id="cb33-18" title="18">     <span class="co">*</span> 展示视频广告</a>
<a class="sourceLine" id="cb33-19" title="19">     <span class="co">*/</span></a>
<a class="sourceLine" id="cb33-20" title="20">    <span class="at">@MainThread</span></a>
<a class="sourceLine" id="cb33-21" title="21">    <span class="dt">void</span> <span class="fu">showRewardVideoAd</span>(Activity var1);</a>
<a class="sourceLine" id="cb33-22" title="22">    </a>
<a class="sourceLine" id="cb33-23" title="23">     <span class="co">/**</span></a>
<a class="sourceLine" id="cb33-24" title="24">     <span class="co">*</span> 展示广告</a>
<a class="sourceLine" id="cb33-25" title="25">     <span class="co">* </span><span class="an">@param activity </span> 宿主activity</a>
<a class="sourceLine" id="cb33-26" title="26">     <span class="co">*</span> <span class="an">@param ritScenes </span>广告展示的场景</a>
<a class="sourceLine" id="cb33-27" title="27">     <span class="co">*</span> <span class="an">@param scenes </span>   广告展示场景为 CUSTOMIZE_SCENES 时，自定义的场景信息</a>
<a class="sourceLine" id="cb33-28" title="28">     <span class="co">*/</span></a>
<a class="sourceLine" id="cb33-29" title="29">    <span class="dt">void</span> <span class="fu">showRewardVideoAd</span>(Activity activity,TTAdConstant.<span class="fu">RitScenes</span> ritScenes,<span class="bu">String</span> scenes);</a>
<a class="sourceLine" id="cb33-30" title="30"></a>
<a class="sourceLine" id="cb33-31" title="31">    <span class="co">/**</span></a>
<a class="sourceLine" id="cb33-32" title="32">     <span class="co">*</span> 设置是否在视频播放页面展示下载bar</a>
<a class="sourceLine" id="cb33-33" title="33">     <span class="co">*/</span></a>
<a class="sourceLine" id="cb33-34" title="34">    <span class="dt">void</span> <span class="fu">setShowDownLoadBar</span>(<span class="dt">boolean</span> var1);</a>
<a class="sourceLine" id="cb33-35" title="35">    </a>
<a class="sourceLine" id="cb33-36" title="36">    </a>
<a class="sourceLine" id="cb33-37" title="37">   <span class="co">/**</span></a>
<a class="sourceLine" id="cb33-38" title="38">     <span class="co">*</span> 返回广告真实类型：</a>
<a class="sourceLine" id="cb33-39" title="39">     <span class="co">*</span> TTAdConstant<span class="co">.</span>AD_TYPE_UNKNOWN <span class="co">//</span>未知类型</a>
<a class="sourceLine" id="cb33-40" title="40">     <span class="co">*</span> TTAdConstant<span class="co">.</span>AD_TYPE_COMMON_VIDEO <span class="co">//</span>普通视频类型</a>
<a class="sourceLine" id="cb33-41" title="41">     <span class="co">*</span> TTAdConstant<span class="co">.</span>AD_TYPE_PLAYABLE_VIDEO <span class="co">//</span>video <span class="co">+</span> playable 类型</a>
<a class="sourceLine" id="cb33-42" title="42">     <span class="co">*</span> TTAdConstant<span class="co">.</span>AD_TYPE_PLAYABLE <span class="co">//</span>playable类型</a>
<a class="sourceLine" id="cb33-43" title="43">     <span class="co">* @</span>return</a>
<a class="sourceLine" id="cb33-44" title="44">     <span class="co">*/</span></a>
<a class="sourceLine" id="cb33-45" title="45">   <span class="dt">int</span> <span class="fu">getRewardVideoAdType</span>();</a>
<a class="sourceLine" id="cb33-46" title="46"></a>
<a class="sourceLine" id="cb33-47" title="47"></a>
<a class="sourceLine" id="cb33-48" title="48">    <span class="co">/**</span></a>
<a class="sourceLine" id="cb33-49" title="49">     <span class="co">*</span> 视频交互回调接口</a>
<a class="sourceLine" id="cb33-50" title="50">     <span class="co">*/</span></a>
<a class="sourceLine" id="cb33-51" title="51">    <span class="kw">public</span> <span class="kw">interface</span> RewardAdInteractionListener {</a>
<a class="sourceLine" id="cb33-52" title="52">        <span class="co">//视频广告展示回调</span></a>
<a class="sourceLine" id="cb33-53" title="53">        <span class="dt">void</span> <span class="fu">onAdShow</span>();</a>
<a class="sourceLine" id="cb33-54" title="54"></a>
<a class="sourceLine" id="cb33-55" title="55">        <span class="co">//广告的下载bar点击回调</span></a>
<a class="sourceLine" id="cb33-56" title="56">        <span class="dt">void</span> <span class="fu">onAdVideoBarClick</span>();</a>
<a class="sourceLine" id="cb33-57" title="57"></a>
<a class="sourceLine" id="cb33-58" title="58">        <span class="co">//视频广告关闭回调</span></a>
<a class="sourceLine" id="cb33-59" title="59">        <span class="dt">void</span> <span class="fu">onAdClose</span>();</a>
<a class="sourceLine" id="cb33-60" title="60"></a>
<a class="sourceLine" id="cb33-61" title="61">        <span class="co">//视频广告播放完毕回调</span></a>
<a class="sourceLine" id="cb33-62" title="62">        <span class="dt">void</span> <span class="fu">onVideoComplete</span>();</a>
<a class="sourceLine" id="cb33-63" title="63"></a>
<a class="sourceLine" id="cb33-64" title="64">        <span class="co">//视频广告播完验证奖励有效性回调，参数分别为是否有效，奖励数量，奖励名称</span></a>
<a class="sourceLine" id="cb33-65" title="65">        <span class="dt">void</span> <span class="fu">onRewardVerify</span>(<span class="dt">boolean</span> var1, <span class="dt">int</span> var2, <span class="bu">String</span> var3);</a>
<a class="sourceLine" id="cb33-66" title="66">    }</a>
<a class="sourceLine" id="cb33-67" title="67">}</a></code></pre></div>
<h4 id="加载激励视频广告">2.9.2 加载激励视频广告</h4>
<p>接入方可调用TTAdNative.loadRewardVideoAdA（dSlot var1, <span class="citation" data-cites="NonNull">@NonNull</span> TTAdNative.RewardVideoAdListener var2)异步加载激励视频广告，adslot为请求广告的信息，RewardVideoAdListener为广告加载成功或失败的回调。</p>
<div class="sourceCode" id="cb34"><pre class="sourceCode java"><code class="sourceCode java"><a class="sourceLine" id="cb34-1" title="1">AdSlot adSlot = <span class="kw">new</span> AdSlot.<span class="fu">Builder</span>()</a>
<a class="sourceLine" id="cb34-2" title="2">                .<span class="fu">setCodeId</span>(<span class="st">&quot;901121430&quot;</span>)</a>
<a class="sourceLine" id="cb34-3" title="3">                .<span class="fu">setSupportDeepLink</span>(<span class="kw">true</span>)</a>
<a class="sourceLine" id="cb34-4" title="4">                .<span class="fu">setAdCount</span>(<span class="dv">2</span>)</a>
<a class="sourceLine" id="cb34-5" title="5">                <span class="co">//个性化模板广告需要设置期望个性化模板广告的大小,单位dp,激励视频场景，只要设置的值大于0即可</span></a>
<a class="sourceLine" id="cb34-6" title="6">                .<span class="fu">setExpressViewAcceptedSize</span>(<span class="dv">500</span>,<span class="dv">500</span>)</a>
<a class="sourceLine" id="cb34-7" title="7">                .<span class="fu">setImageAcceptedSize</span>(<span class="dv">1080</span>, <span class="dv">1920</span>)</a>
<a class="sourceLine" id="cb34-8" title="8">                .<span class="fu">setRewardName</span>(<span class="st">&quot;金币&quot;</span>) <span class="co">//奖励的名称</span></a>
<a class="sourceLine" id="cb34-9" title="9">                .<span class="fu">setRewardAmount</span>(<span class="dv">3</span>)   <span class="co">//奖励的数量</span></a>
<a class="sourceLine" id="cb34-10" title="10">                <span class="co">//必传参数，表来标识应用侧唯一用户；若非服务器回调模式或不需sdk透传</span></a>
<a class="sourceLine" id="cb34-11" title="11">                <span class="co">//可设置为空字符串</span></a>
<a class="sourceLine" id="cb34-12" title="12">                .<span class="fu">setUserID</span>(<span class="st">&quot;user123&quot;</span>)</a>
<a class="sourceLine" id="cb34-13" title="13">                .<span class="fu">setOrientation</span>(orientation)  <span class="co">//设置期望视频播放的方向，为TTAdConstant.HORIZONTAL或TTAdConstant.VERTICAL</span></a>
<a class="sourceLine" id="cb34-14" title="14">                .<span class="fu">setMediaExtra</span>(<span class="st">&quot;media_extra&quot;</span>) <span class="co">//用户透传的信息，可不传</span></a>
<a class="sourceLine" id="cb34-15" title="15">                .<span class="fu">build</span>();</a>
<a class="sourceLine" id="cb34-16" title="16">        mTTAdNative.<span class="fu">loadRewardVideoAd</span>(adSlot, <span class="kw">new</span> TTAdNative.<span class="fu">RewardVideoAdListener</span>() {</a>
<a class="sourceLine" id="cb34-17" title="17">            <span class="at">@Override</span></a>
<a class="sourceLine" id="cb34-18" title="18">            <span class="kw">public</span> <span class="dt">void</span> <span class="fu">onError</span>(<span class="dt">int</span> code, <span class="bu">String</span> message) {</a>
<a class="sourceLine" id="cb34-19" title="19">                Toast.<span class="fu">makeText</span>(RewardVideoActivity.<span class="fu">this</span>, message, Toast.<span class="fu">LENGTH_SHORT</span>).<span class="fu">show</span>();</a>
<a class="sourceLine" id="cb34-20" title="20">            }</a>
<a class="sourceLine" id="cb34-21" title="21">            <span class="co">//视频广告加载后的视频文件资源缓存到本地的回调</span></a>
<a class="sourceLine" id="cb34-22" title="22">            <span class="at">@Override</span></a>
<a class="sourceLine" id="cb34-23" title="23">            <span class="kw">public</span> <span class="dt">void</span> <span class="fu">onRewardVideoCached</span>() {</a>
<a class="sourceLine" id="cb34-24" title="24">                 Toast.<span class="fu">makeText</span>(RewardVideoActivity.<span class="fu">this</span>, <span class="st">&quot;rewardVideoAd video cached&quot;</span>, Toast.<span class="fu">LENGTH_SHORT</span>).<span class="fu">show</span>();</a>
<a class="sourceLine" id="cb34-25" title="25">            }</a>
<a class="sourceLine" id="cb34-26" title="26">            <span class="co">//视频广告素材加载到，如title,视频url等，不包括视频文件</span></a>
<a class="sourceLine" id="cb34-27" title="27">            <span class="at">@Override</span></a>
<a class="sourceLine" id="cb34-28" title="28">            <span class="kw">public</span> <span class="dt">void</span> <span class="fu">onRewardVideoAdLoad</span>(TTRewardVideoAd ad) {</a>
<a class="sourceLine" id="cb34-29" title="29">                Toast.<span class="fu">makeText</span>(RewardVideoActivity.<span class="fu">this</span>, <span class="st">&quot;rewardVideoAd loaded&quot;</span>, Toast.<span class="fu">LENGTH_SHORT</span>).<span class="fu">show</span>();</a>
<a class="sourceLine" id="cb34-30" title="30">                mttRewardVideoAd = ad;</a>
<a class="sourceLine" id="cb34-31" title="31">                <span class="co">//mttRewardVideoAd.setShowDownLoadBar(false);</span></a>
<a class="sourceLine" id="cb34-32" title="32">                mttRewardVideoAd.<span class="fu">setRewardAdInteractionListener</span>(<span class="kw">new</span> TTRewardVideoAd.<span class="fu">RewardAdInteractionListener</span>() {</a>
<a class="sourceLine" id="cb34-33" title="33"></a>
<a class="sourceLine" id="cb34-34" title="34">                    <span class="at">@Override</span></a>
<a class="sourceLine" id="cb34-35" title="35">                    <span class="kw">public</span> <span class="dt">void</span> <span class="fu">onAdShow</span>() {</a>
<a class="sourceLine" id="cb34-36" title="36">                        Toast.<span class="fu">makeText</span>(RewardVideoActivity.<span class="fu">this</span>, <span class="st">&quot;rewardVideoAd show&quot;</span>, Toast.<span class="fu">LENGTH_SHORT</span>).<span class="fu">show</span>();</a>
<a class="sourceLine" id="cb34-37" title="37">                    }</a>
<a class="sourceLine" id="cb34-38" title="38"></a>
<a class="sourceLine" id="cb34-39" title="39">                    <span class="at">@Override</span></a>
<a class="sourceLine" id="cb34-40" title="40">                    <span class="kw">public</span> <span class="dt">void</span> <span class="fu">onAdVideoBarClick</span>() {</a>
<a class="sourceLine" id="cb34-41" title="41">                        Toast.<span class="fu">makeText</span>(RewardVideoActivity.<span class="fu">this</span>, <span class="st">&quot;rewardVideoAd bar click&quot;</span>, Toast.<span class="fu">LENGTH_SHORT</span>).<span class="fu">show</span>();</a>
<a class="sourceLine" id="cb34-42" title="42">                    }</a>
<a class="sourceLine" id="cb34-43" title="43"></a>
<a class="sourceLine" id="cb34-44" title="44">                    <span class="at">@Override</span></a>
<a class="sourceLine" id="cb34-45" title="45">                    <span class="kw">public</span> <span class="dt">void</span> <span class="fu">onAdClose</span>() {</a>
<a class="sourceLine" id="cb34-46" title="46">                        Toast.<span class="fu">makeText</span>(RewardVideoActivity.<span class="fu">this</span>, <span class="st">&quot;rewardVideoAd close&quot;</span>, Toast.<span class="fu">LENGTH_SHORT</span>).<span class="fu">show</span>();</a>
<a class="sourceLine" id="cb34-47" title="47">                    }</a>
<a class="sourceLine" id="cb34-48" title="48"></a>
<a class="sourceLine" id="cb34-49" title="49">                    <span class="at">@Override</span></a>
<a class="sourceLine" id="cb34-50" title="50">                    <span class="kw">public</span> <span class="dt">void</span> <span class="fu">onVideoComplete</span>() {</a>
<a class="sourceLine" id="cb34-51" title="51">                        Toast.<span class="fu">makeText</span>(RewardVideoActivity.<span class="fu">this</span>, <span class="st">&quot;rewardVideoAd complete&quot;</span>, Toast.<span class="fu">LENGTH_SHORT</span>).<span class="fu">show</span>();</a>
<a class="sourceLine" id="cb34-52" title="52">                    }</a>
<a class="sourceLine" id="cb34-53" title="53"></a>
<a class="sourceLine" id="cb34-54" title="54">                    <span class="at">@Override</span></a>
<a class="sourceLine" id="cb34-55" title="55">                    <span class="kw">public</span> <span class="dt">void</span> <span class="fu">onRewardVerify</span>(<span class="dt">boolean</span> rewardVerify, <span class="dt">int</span> rewardAmount, <span class="bu">String</span> rewardName) {</a>
<a class="sourceLine" id="cb34-56" title="56">                        Toast.<span class="fu">makeText</span>(RewardVideoActivity.<span class="fu">this</span>, <span class="st">&quot;verify:&quot;</span>+rewardVerify+<span class="st">&quot; amount:&quot;</span>+rewardAmount+</a>
<a class="sourceLine" id="cb34-57" title="57">                                <span class="st">&quot; name:&quot;</span>+rewardName,</a>
<a class="sourceLine" id="cb34-58" title="58">                                Toast.<span class="fu">LENGTH_SHORT</span>).<span class="fu">show</span>();</a>
<a class="sourceLine" id="cb34-59" title="59">                    }</a>
<a class="sourceLine" id="cb34-60" title="60">                });</a>
<a class="sourceLine" id="cb34-61" title="61">                mttRewardVideoAd.<span class="fu">setDownloadListener</span>(<span class="kw">new</span> <span class="fu">TTAppDownloadListener</span>() {</a>
<a class="sourceLine" id="cb34-62" title="62">                    <span class="at">@Override</span></a>
<a class="sourceLine" id="cb34-63" title="63">                    <span class="kw">public</span> <span class="dt">void</span> <span class="fu">onIdle</span>() {</a>
<a class="sourceLine" id="cb34-64" title="64"></a>
<a class="sourceLine" id="cb34-65" title="65">                    }</a>
<a class="sourceLine" id="cb34-66" title="66"></a>
<a class="sourceLine" id="cb34-67" title="67">                    <span class="at">@Override</span></a>
<a class="sourceLine" id="cb34-68" title="68">                    <span class="kw">public</span> <span class="dt">void</span> <span class="fu">onDownloadActive</span>(<span class="dt">long</span> totalBytes, <span class="dt">long</span> currBytes, <span class="bu">String</span> fileName, <span class="bu">String</span> appName) {</a>
<a class="sourceLine" id="cb34-69" title="69"></a>
<a class="sourceLine" id="cb34-70" title="70">                    }</a>
<a class="sourceLine" id="cb34-71" title="71"></a>
<a class="sourceLine" id="cb34-72" title="72">                    <span class="at">@Override</span></a>
<a class="sourceLine" id="cb34-73" title="73">                    <span class="kw">public</span> <span class="dt">void</span> <span class="fu">onDownloadPaused</span>(<span class="dt">long</span> totalBytes, <span class="dt">long</span> currBytes, <span class="bu">String</span> fileName, <span class="bu">String</span> appName) {</a>
<a class="sourceLine" id="cb34-74" title="74"></a>
<a class="sourceLine" id="cb34-75" title="75">                    }</a>
<a class="sourceLine" id="cb34-76" title="76"></a>
<a class="sourceLine" id="cb34-77" title="77">                    <span class="at">@Override</span></a>
<a class="sourceLine" id="cb34-78" title="78">                    <span class="kw">public</span> <span class="dt">void</span> <span class="fu">onDownloadFailed</span>(<span class="dt">long</span> totalBytes, <span class="dt">long</span> currBytes, <span class="bu">String</span> fileName, <span class="bu">String</span> appName) {</a>
<a class="sourceLine" id="cb34-79" title="79"></a>
<a class="sourceLine" id="cb34-80" title="80">                    }</a>
<a class="sourceLine" id="cb34-81" title="81"></a>
<a class="sourceLine" id="cb34-82" title="82">                    <span class="at">@Override</span></a>
<a class="sourceLine" id="cb34-83" title="83">                    <span class="kw">public</span> <span class="dt">void</span> <span class="fu">onDownloadFinished</span>(<span class="dt">long</span> totalBytes, <span class="bu">String</span> fileName, <span class="bu">String</span> appName) {</a>
<a class="sourceLine" id="cb34-84" title="84"></a>
<a class="sourceLine" id="cb34-85" title="85">                    }</a>
<a class="sourceLine" id="cb34-86" title="86"></a>
<a class="sourceLine" id="cb34-87" title="87">                    <span class="at">@Override</span></a>
<a class="sourceLine" id="cb34-88" title="88">                    <span class="kw">public</span> <span class="dt">void</span> <span class="fu">onInstalled</span>(<span class="bu">String</span> fileName, <span class="bu">String</span> appName) {</a>
<a class="sourceLine" id="cb34-89" title="89"></a>
<a class="sourceLine" id="cb34-90" title="90">                    }</a>
<a class="sourceLine" id="cb34-91" title="91">                });</a>
<a class="sourceLine" id="cb34-92" title="92">            }</a>
<a class="sourceLine" id="cb34-93" title="93">        });</a></code></pre></div>
<h4 id="展示视频广告">2.9.3 展示视频广告</h4>
<p>接入方可调用TTAdNative.loadRewardVideoAdA（dSlot var1, <span class="citation" data-cites="NonNull">@NonNull</span> TTAdNative.RewardVideoAdListener var2)异步加载激励视频广告，adslot为请求广告的信息，RewardVideoAdListener为广告加载成功或失败的回调。</p>
<div class="sourceCode" id="cb35"><pre class="sourceCode java"><code class="sourceCode java"><a class="sourceLine" id="cb35-1" title="1">mttRewardVideoAd.<span class="fu">showRewardVideoAd</span>(RewardVideoActivity.<span class="fu">this</span>);</a></code></pre></div>
<p>具体使用请参考demo示例。</p>
<h4 id="服务器到服务器回调">2.9.4 服务器到服务器回调</h4>
<p>服务器到服务器回调让您判定是否提供奖励给观看广告的用户。当用户成功看完广告时，您可以在头条媒体平台配置从头条服务器到您自己的服务器的回调链接，以通知您用户完成了操作。</p>
<h5 id="回调方式说明">回调方式说明</h5>
<p>头条服务器会以 GET 方式请求第三方服务的回调链接，并拼接以下参数回传：</p>
<p><code>user_id=%s&amp;trans_id=%s&amp;reward_name=%s&amp;reward_amount=%d&amp;extra=%s&amp;sign=%s</code></p>
<table>
<thead>
<tr class="header">
<th>字段名称</th>
<th>字段定义</th>
<th>字段类型</th>
<th>备注</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td>sign</td>
<td>签名</td>
<td>string</td>
<td>签名</td>
</tr>
<tr class="even">
<td>user_id</td>
<td>用户id</td>
<td>string</td>
<td>调用SDK透传，应用对用户的唯一标识</td>
</tr>
<tr class="odd">
<td>trans_id</td>
<td>交易id</td>
<td>string</td>
<td>完成观看的唯一交易ID</td>
</tr>
<tr class="even">
<td>reward_amount</td>
<td>奖励数量</td>
<td>int</td>
<td>媒体平台配置或调用SDK传入</td>
</tr>
<tr class="odd">
<td>reward_name</td>
<td>奖励名称</td>
<td>string</td>
<td>媒体平台配置或调用SDK传入</td>
</tr>
<tr class="even">
<td>extra</td>
<td>Extra</td>
<td>string</td>
<td>调用SDK传入并透传，如无需要则为空</td>
</tr>
</tbody>
</table>
<h5 id="签名生成方式">签名生成方式</h5>
<p>appSecurityKey: 您在头条媒体平台新建奖励视频代码位获取到的密钥 transId：交易id sign = sha256(appSecurityKey:transId)</p>
<p>Python 示例：</p>
<div class="sourceCode" id="cb36"><pre class="sourceCode python"><code class="sourceCode python"><a class="sourceLine" id="cb36-1" title="1"><span class="im">import</span> hashlib</a>
<a class="sourceLine" id="cb36-2" title="2"></a>
<a class="sourceLine" id="cb36-3" title="3"><span class="cf">if</span> <span class="va">__name__</span> <span class="op">==</span> <span class="st">&quot;__main__&quot;</span>:</a>
<a class="sourceLine" id="cb36-4" title="4">    trans_id <span class="op">=</span> <span class="st">&quot;6FEB23ACB0374985A2A52D282EDD5361u6643&quot;</span></a>
<a class="sourceLine" id="cb36-5" title="5">    app_security_key <span class="op">=</span> <span class="st">&quot;7ca31ab0a59d69a42dd8abc7cf2d8fbd&quot;</span></a>
<a class="sourceLine" id="cb36-6" title="6">    check_sign_raw <span class="op">=</span> <span class="st">&quot;</span><span class="sc">%s</span><span class="st">:</span><span class="sc">%s</span><span class="st">&quot;</span> <span class="op">%</span> (app_security_key, trans_id)</a>
<a class="sourceLine" id="cb36-7" title="7">    sign <span class="op">=</span> hashlib.sha256(check_sign_raw).hexdigest()</a></code></pre></div>
<h5 id="返回约定">返回约定</h5>
<p>返回 json 数据，字段如下：</p>
<table>
<thead>
<tr class="header">
<th>字段名称</th>
<th>字段定义</th>
<th>字段类型</th>
<th>备注</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td>isValid</td>
<td>校验结果</td>
<td>bool</td>
<td>判定结果，是否发放奖励</td>
</tr>
</tbody>
</table>
<p>示例：</p>
<pre><code>{
    &quot;isValid&quot;: true
}</code></pre>
<h3 id="接入全屏视频广告ttfullscreenvideoad">2.10 接入全屏视频广告（TTFullScreenVideoAd）</h3>
<p>本SDK为接入方提供全屏视频广告，该广告的效果播放全屏的视频，视频一定时间后可跳过，无需全程观看完。 支持的广告尺寸： 全屏横屏播放和竖屏，默认横屏</p>
<h4 id="ttfullscreenvideoad接口说明">2.10.1 TTFullScreenVideoAd接口说明：</h4>
<div class="sourceCode" id="cb38"><pre class="sourceCode java"><code class="sourceCode java"><a class="sourceLine" id="cb38-1" title="1"><span class="kw">public</span> <span class="kw">interface</span> TTFullScreenVideoAd {</a>
<a class="sourceLine" id="cb38-2" title="2">    <span class="co">/**</span></a>
<a class="sourceLine" id="cb38-3" title="3">     <span class="co">*</span> 注册插屏广告交互回调</a>
<a class="sourceLine" id="cb38-4" title="4">     <span class="co">*</span></a>
<a class="sourceLine" id="cb38-5" title="5">     <span class="co">* </span><span class="an">@param listener </span>交互监听器</a>
<a class="sourceLine" id="cb38-6" title="6">     <span class="co">*/</span></a>
<a class="sourceLine" id="cb38-7" title="7">    <span class="dt">void</span> <span class="fu">setFullScreenVideoAdInteractionListener</span>(FullScreenVideoAdInteractionListener listener);</a>
<a class="sourceLine" id="cb38-8" title="8"></a>
<a class="sourceLine" id="cb38-9" title="9">    <span class="co">/**</span></a>
<a class="sourceLine" id="cb38-10" title="10">     <span class="co">*</span> 注册广告的下载回调</a>
<a class="sourceLine" id="cb38-11" title="11">     <span class="co">*</span></a>
<a class="sourceLine" id="cb38-12" title="12">     <span class="co">* </span><span class="an">@param listener </span>下载状态回调</a>
<a class="sourceLine" id="cb38-13" title="13">     <span class="co">*/</span></a>
<a class="sourceLine" id="cb38-14" title="14">    <span class="dt">void</span> <span class="fu">setDownloadListener</span>(TTAppDownloadListener listener);</a>
<a class="sourceLine" id="cb38-15" title="15"></a>
<a class="sourceLine" id="cb38-16" title="16">    <span class="co">/**</span></a>
<a class="sourceLine" id="cb38-17" title="17">     <span class="co">*</span> 得到广告的交互类型</a>
<a class="sourceLine" id="cb38-18" title="18">     <span class="co">*</span></a>
<a class="sourceLine" id="cb38-19" title="19">     <span class="co">* </span><span class="an">@return </span><span class="co">2在</span>浏览器内打开 （普通类型）3落地页（普通类型），<span class="co">4:</span>应用下载，5:拨打电话 <span class="co">-1</span> 未知类型</a>
<a class="sourceLine" id="cb38-20" title="20">     <span class="co">*/</span></a>
<a class="sourceLine" id="cb38-21" title="21">    <span class="dt">int</span> <span class="fu">getInteractionType</span>();</a>
<a class="sourceLine" id="cb38-22" title="22"></a>
<a class="sourceLine" id="cb38-23" title="23">    <span class="co">/**</span></a>
<a class="sourceLine" id="cb38-24" title="24">     <span class="co">* </span><span class="an">@param activity </span>宿主activity<span class="co">,</span>用户判断宿主是否finishing</a>
<a class="sourceLine" id="cb38-25" title="25">     <span class="co">*/</span></a>
<a class="sourceLine" id="cb38-26" title="26">    <span class="at">@MainThread</span></a>
<a class="sourceLine" id="cb38-27" title="27">    <span class="dt">void</span> <span class="fu">showFullScreenVideoAd</span>(Activity activity);</a>
<a class="sourceLine" id="cb38-28" title="28">    </a>
<a class="sourceLine" id="cb38-29" title="29">    <span class="co">/**</span></a>
<a class="sourceLine" id="cb38-30" title="30">     <span class="co">*</span> 展示广告</a>
<a class="sourceLine" id="cb38-31" title="31">     <span class="co">* </span><span class="an">@param activity </span> 宿主activity</a>
<a class="sourceLine" id="cb38-32" title="32">     <span class="co">*</span> <span class="an">@param ritScenes </span>广告展示的场景</a>
<a class="sourceLine" id="cb38-33" title="33">     <span class="co">*</span> <span class="an">@param scenes </span>   广告展示场景为 CUSTOMIZE_SCENES 时，自定义的场景信息</a>
<a class="sourceLine" id="cb38-34" title="34">     <span class="co">*/</span></a>
<a class="sourceLine" id="cb38-35" title="35">    <span class="dt">void</span> <span class="fu">showFullScreenVideoAd</span>(Activity activity, TTAdConstant.<span class="fu">RitScenes</span> ritScenes, <span class="bu">String</span> scenes);</a>
<a class="sourceLine" id="cb38-36" title="36"></a>
<a class="sourceLine" id="cb38-37" title="37">    <span class="dt">void</span> <span class="fu">setShowDownLoadBar</span>(<span class="dt">boolean</span> showDownLoadBar);</a>
<a class="sourceLine" id="cb38-38" title="38">    </a>
<a class="sourceLine" id="cb38-39" title="39">    <span class="co">/**</span></a>
<a class="sourceLine" id="cb38-40" title="40">     <span class="co">*</span> 返回广告真实类型：</a>
<a class="sourceLine" id="cb38-41" title="41">     <span class="co">*</span> TTAdConstant<span class="co">.</span>AD_TYPE_UNKNOWN <span class="co">//</span>未知类型</a>
<a class="sourceLine" id="cb38-42" title="42">     <span class="co">*</span> TTAdConstant<span class="co">.</span>AD_TYPE_COMMON_VIDEO <span class="co">//</span>普通视频类型</a>
<a class="sourceLine" id="cb38-43" title="43">     <span class="co">*</span> TTAdConstant<span class="co">.</span>AD_TYPE_PLAYABLE_VIDEO <span class="co">//</span>video <span class="co">+</span> playable 类型</a>
<a class="sourceLine" id="cb38-44" title="44">     <span class="co">*</span> TTAdConstant<span class="co">.</span>AD_TYPE_PLAYABLE <span class="co">//</span>playable类型</a>
<a class="sourceLine" id="cb38-45" title="45">     <span class="co">* @</span>return</a>
<a class="sourceLine" id="cb38-46" title="46">     <span class="co">*/</span></a>
<a class="sourceLine" id="cb38-47" title="47">    <span class="dt">int</span> <span class="fu">getFullVideoAdType</span>();</a>
<a class="sourceLine" id="cb38-48" title="48"></a>
<a class="sourceLine" id="cb38-49" title="49">    <span class="co">/**</span></a>
<a class="sourceLine" id="cb38-50" title="50">     <span class="co">*</span> 全屏视频广告交互监听器</a>
<a class="sourceLine" id="cb38-51" title="51">     <span class="co">*/</span></a>
<a class="sourceLine" id="cb38-52" title="52">    <span class="kw">interface</span> FullScreenVideoAdInteractionListener {</a>
<a class="sourceLine" id="cb38-53" title="53">        <span class="co">/**</span></a>
<a class="sourceLine" id="cb38-54" title="54">         <span class="co">*</span> 广告的展示回调 每个广告仅回调一次</a>
<a class="sourceLine" id="cb38-55" title="55">         <span class="co">*/</span></a>
<a class="sourceLine" id="cb38-56" title="56">        <span class="dt">void</span> <span class="fu">onAdShow</span>();</a>
<a class="sourceLine" id="cb38-57" title="57"></a>
<a class="sourceLine" id="cb38-58" title="58">        <span class="co">/**</span></a>
<a class="sourceLine" id="cb38-59" title="59">         <span class="co">*</span> 广告的下载bar点击回调</a>
<a class="sourceLine" id="cb38-60" title="60">         <span class="co">*/</span></a>
<a class="sourceLine" id="cb38-61" title="61">        <span class="dt">void</span> <span class="fu">onAdVideoBarClick</span>();</a>
<a class="sourceLine" id="cb38-62" title="62"></a>
<a class="sourceLine" id="cb38-63" title="63">        <span class="co">/**</span></a>
<a class="sourceLine" id="cb38-64" title="64">         <span class="co">*</span> 广告关闭的回调</a>
<a class="sourceLine" id="cb38-65" title="65">         <span class="co">*/</span></a>
<a class="sourceLine" id="cb38-66" title="66">        <span class="dt">void</span> <span class="fu">onAdClose</span>();</a>
<a class="sourceLine" id="cb38-67" title="67"></a>
<a class="sourceLine" id="cb38-68" title="68">        <span class="co">/**</span></a>
<a class="sourceLine" id="cb38-69" title="69">         <span class="co">*</span> 视频播放完毕的回调</a>
<a class="sourceLine" id="cb38-70" title="70">         <span class="co">*/</span></a>
<a class="sourceLine" id="cb38-71" title="71">        <span class="dt">void</span> <span class="fu">onVideoComplete</span>();</a>
<a class="sourceLine" id="cb38-72" title="72"></a>
<a class="sourceLine" id="cb38-73" title="73">        <span class="co">/**</span></a>
<a class="sourceLine" id="cb38-74" title="74">         <span class="co">*</span> 跳过视频播放</a>
<a class="sourceLine" id="cb38-75" title="75">         <span class="co">*/</span></a>
<a class="sourceLine" id="cb38-76" title="76">        <span class="dt">void</span> <span class="fu">onSkippedVideo</span>();</a>
<a class="sourceLine" id="cb38-77" title="77"></a>
<a class="sourceLine" id="cb38-78" title="78">    }</a>
<a class="sourceLine" id="cb38-79" title="79">}</a></code></pre></div>
<h4 id="加载全屏视频广告">2.10.2 加载全屏视频广告</h4>
<p>接入方可调用<code>loadFullScreenVideoAd(AdSlot adSlot, @NonNull FullScreenVideoAdListener listener)</code>异步加载全屏视频广告，adslot为请求广告的信息，FullScreenVideoAdListener为广告加载成功或失败的回调。</p>
<div class="sourceCode" id="cb39"><pre class="sourceCode java"><code class="sourceCode java"><a class="sourceLine" id="cb39-1" title="1"> <span class="co">//设置广告参数</span></a>
<a class="sourceLine" id="cb39-2" title="2"> AdSlot adSlot = <span class="kw">new</span> AdSlot.<span class="fu">Builder</span>()</a>
<a class="sourceLine" id="cb39-3" title="3">                .<span class="fu">setCodeId</span>(codeId)</a>
<a class="sourceLine" id="cb39-4" title="4">                .<span class="fu">setSupportDeepLink</span>(<span class="kw">true</span>)</a>
<a class="sourceLine" id="cb39-5" title="5">                <span class="co">//个性化模板广告需要设置期望个性化模板广告的大小,单位dp,全屏视频场景，只要设置的值大于0即可</span></a>
<a class="sourceLine" id="cb39-6" title="6">                .<span class="fu">setExpressViewAcceptedSize</span>(<span class="dv">500</span>,<span class="dv">500</span>)</a>
<a class="sourceLine" id="cb39-7" title="7">                .<span class="fu">setImageAcceptedSize</span>(<span class="dv">1080</span>, <span class="dv">1920</span>)</a>
<a class="sourceLine" id="cb39-8" title="8">                .<span class="fu">setOrientation</span>(orientation)</a>
<a class="sourceLine" id="cb39-9" title="9">                .<span class="fu">build</span>();</a>
<a class="sourceLine" id="cb39-10" title="10">       <span class="co">//加载全屏视频</span></a>
<a class="sourceLine" id="cb39-11" title="11">        mTTAdNative.<span class="fu">loadFullScreenVideoAd</span>(adSlot, <span class="kw">new</span> TTAdNative.<span class="fu">FullScreenVideoAdListener</span>() {</a>
<a class="sourceLine" id="cb39-12" title="12">            <span class="at">@Override</span></a>
<a class="sourceLine" id="cb39-13" title="13">            <span class="kw">public</span> <span class="dt">void</span> <span class="fu">onError</span>(<span class="dt">int</span> code, <span class="bu">String</span> message) {</a>
<a class="sourceLine" id="cb39-14" title="14">                TToast.<span class="fu">show</span>(FullScreenVideoActivity.<span class="fu">this</span>, message);</a>
<a class="sourceLine" id="cb39-15" title="15">            }</a>
<a class="sourceLine" id="cb39-16" title="16"></a>
<a class="sourceLine" id="cb39-17" title="17">            <span class="at">@Override</span></a>
<a class="sourceLine" id="cb39-18" title="18">            <span class="kw">public</span> <span class="dt">void</span> <span class="fu">onFullScreenVideoAdLoad</span>(TTFullScreenVideoAd ad) {</a>
<a class="sourceLine" id="cb39-19" title="19">                TToast.<span class="fu">show</span>(FullScreenVideoActivity.<span class="fu">this</span>, <span class="st">&quot;FullVideoAd loaded&quot;</span>);</a>
<a class="sourceLine" id="cb39-20" title="20">                mttFullVideoAd = ad;</a>
<a class="sourceLine" id="cb39-21" title="21">                mttFullVideoAd.<span class="fu">setFullScreenVideoAdInteractionListener</span>(<span class="kw">new</span> TTFullScreenVideoAd.<span class="fu">FullScreenVideoAdInteractionListener</span>() {</a>
<a class="sourceLine" id="cb39-22" title="22"></a>
<a class="sourceLine" id="cb39-23" title="23">                    <span class="at">@Override</span></a>
<a class="sourceLine" id="cb39-24" title="24">                    <span class="kw">public</span> <span class="dt">void</span> <span class="fu">onAdShow</span>() {</a>
<a class="sourceLine" id="cb39-25" title="25">                        TToast.<span class="fu">show</span>(FullScreenVideoActivity.<span class="fu">this</span>, <span class="st">&quot;FullVideoAd show&quot;</span>);</a>
<a class="sourceLine" id="cb39-26" title="26">                    }</a>
<a class="sourceLine" id="cb39-27" title="27"></a>
<a class="sourceLine" id="cb39-28" title="28">                    <span class="at">@Override</span></a>
<a class="sourceLine" id="cb39-29" title="29">                    <span class="kw">public</span> <span class="dt">void</span> <span class="fu">onAdVideoBarClick</span>() {</a>
<a class="sourceLine" id="cb39-30" title="30">                        TToast.<span class="fu">show</span>(FullScreenVideoActivity.<span class="fu">this</span>, <span class="st">&quot;FullVideoAd bar click&quot;</span>);</a>
<a class="sourceLine" id="cb39-31" title="31">                    }</a>
<a class="sourceLine" id="cb39-32" title="32"></a>
<a class="sourceLine" id="cb39-33" title="33">                    <span class="at">@Override</span></a>
<a class="sourceLine" id="cb39-34" title="34">                    <span class="kw">public</span> <span class="dt">void</span> <span class="fu">onAdClose</span>() {</a>
<a class="sourceLine" id="cb39-35" title="35">                        TToast.<span class="fu">show</span>(FullScreenVideoActivity.<span class="fu">this</span>, <span class="st">&quot;FullVideoAd close&quot;</span>);</a>
<a class="sourceLine" id="cb39-36" title="36">                    }</a>
<a class="sourceLine" id="cb39-37" title="37"></a>
<a class="sourceLine" id="cb39-38" title="38">                    <span class="at">@Override</span></a>
<a class="sourceLine" id="cb39-39" title="39">                    <span class="kw">public</span> <span class="dt">void</span> <span class="fu">onVideoComplete</span>() {</a>
<a class="sourceLine" id="cb39-40" title="40">                        TToast.<span class="fu">show</span>(FullScreenVideoActivity.<span class="fu">this</span>, <span class="st">&quot;FullVideoAd complete&quot;</span>);</a>
<a class="sourceLine" id="cb39-41" title="41">                    }</a>
<a class="sourceLine" id="cb39-42" title="42"></a>
<a class="sourceLine" id="cb39-43" title="43">                    <span class="at">@Override</span></a>
<a class="sourceLine" id="cb39-44" title="44">                    <span class="kw">public</span> <span class="dt">void</span> <span class="fu">onSkippedVideo</span>() {</a>
<a class="sourceLine" id="cb39-45" title="45">                        TToast.<span class="fu">show</span>(FullScreenVideoActivity.<span class="fu">this</span>, <span class="st">&quot;FullVideoAd skipped&quot;</span>);</a>
<a class="sourceLine" id="cb39-46" title="46"></a>
<a class="sourceLine" id="cb39-47" title="47">                    }</a>
<a class="sourceLine" id="cb39-48" title="48"></a>
<a class="sourceLine" id="cb39-49" title="49">                });</a>
<a class="sourceLine" id="cb39-50" title="50">            }</a>
<a class="sourceLine" id="cb39-51" title="51"></a>
<a class="sourceLine" id="cb39-52" title="52">            <span class="at">@Override</span></a>
<a class="sourceLine" id="cb39-53" title="53">            <span class="kw">public</span> <span class="dt">void</span> <span class="fu">onFullScreenVideoCached</span>() {</a>
<a class="sourceLine" id="cb39-54" title="54">                TToast.<span class="fu">show</span>(FullScreenVideoActivity.<span class="fu">this</span>, <span class="st">&quot;FullVideoAd video cached&quot;</span>);</a>
<a class="sourceLine" id="cb39-55" title="55">            }</a>
<a class="sourceLine" id="cb39-56" title="56">        });</a></code></pre></div>
<h4 id="展示视频广告-1">2.10.3 展示视频广告</h4>
<div class="sourceCode" id="cb40"><pre class="sourceCode java"><code class="sourceCode java"><a class="sourceLine" id="cb40-1" title="1">mttFullVideoAd.<span class="fu">showFullScreenVideoAd</span>(FullScreenVideoActivity.<span class="fu">this</span>);</a></code></pre></div>
<p>详细代码请参考demo中的FullScreenVideoActivity。</p>
<h3 id="接入draw竖版视频信息流广告ttdrawfeedad">2.11 接入Draw竖版视频信息流广告（TTDrawFeedAd）</h3>
<p>本SDK为接入方提供竖版视频信息流广告，该广告适合在竖版全屏视频流中使用，接入方可以控制视频暂停或继续播放，默认视频播放不可干预，视频广告相关配置可以在平台设置。 支持的广告尺寸： 全屏竖版。</p>
<h4 id="ttdrawfeedad接口说明">2.11.1 TTDrawFeedAd接口说明：</h4>
<div class="sourceCode" id="cb41"><pre class="sourceCode java"><code class="sourceCode java"><a class="sourceLine" id="cb41-1" title="1"><span class="kw">public</span> <span class="kw">interface</span> TTDrawFeedAd <span class="kw">extends</span> TTFeedAd {</a>
<a class="sourceLine" id="cb41-2" title="2"></a>
<a class="sourceLine" id="cb41-3" title="3">    <span class="co">/**</span></a>
<a class="sourceLine" id="cb41-4" title="4">     <span class="co">*</span> 设置是否允许视频区域响应点击，并且暂停<span class="co">/</span>继续播放</a>
<a class="sourceLine" id="cb41-5" title="5">     <span class="co">*</span></a>
<a class="sourceLine" id="cb41-6" title="6">     <span class="co">* </span><span class="an">@param canInterruptVideoPlay </span>true 可以影响点击<span class="co">,</span> 默认为false</a>
<a class="sourceLine" id="cb41-7" title="7">     <span class="co">*/</span></a>
<a class="sourceLine" id="cb41-8" title="8">    <span class="dt">void</span> <span class="fu">setCanInterruptVideoPlay</span>(<span class="dt">boolean</span> canInterruptVideoPlay);</a>
<a class="sourceLine" id="cb41-9" title="9"></a>
<a class="sourceLine" id="cb41-10" title="10">    <span class="co">/**</span></a>
<a class="sourceLine" id="cb41-11" title="11">     <span class="co">*</span> 设置暂停图标和大小</a>
<a class="sourceLine" id="cb41-12" title="12">     <span class="co">*</span></a>
<a class="sourceLine" id="cb41-13" title="13">     <span class="co">* </span><span class="an">@param pauseIcon</span></a>
<a class="sourceLine" id="cb41-14" title="14">     <span class="co">*</span> <span class="an">@param size </span> 单位为dp<span class="co">,</span> <span class="co">20</span> 到 <span class="co">200之间,</span>默认为 <span class="co">50</span></a>
<a class="sourceLine" id="cb41-15" title="15">     <span class="co">*/</span></a>
<a class="sourceLine" id="cb41-16" title="16">    <span class="dt">void</span> <span class="fu">setPauseIcon</span>(Bitmap pauseIcon, <span class="dt">int</span> size);</a>
<a class="sourceLine" id="cb41-17" title="17"></a>
<a class="sourceLine" id="cb41-18" title="18">     <span class="co">/**</span></a>
<a class="sourceLine" id="cb41-19" title="19">     <span class="co">*</span> draw视频监听回调</a>
<a class="sourceLine" id="cb41-20" title="20">     <span class="co">* </span><span class="an">@param listener</span></a>
<a class="sourceLine" id="cb41-21" title="21">     <span class="co">*/</span></a>
<a class="sourceLine" id="cb41-22" title="22">    <span class="dt">void</span> <span class="fu">setDrawVideoListener</span>(DrawVideoListener listener);</a>
<a class="sourceLine" id="cb41-23" title="23"></a>
<a class="sourceLine" id="cb41-24" title="24">    <span class="kw">interface</span> DrawVideoListener{</a>
<a class="sourceLine" id="cb41-25" title="25">        <span class="co">/**</span></a>
<a class="sourceLine" id="cb41-26" title="26">         <span class="co">*</span> 点击重试按钮</a>
<a class="sourceLine" id="cb41-27" title="27">         <span class="co">*/</span></a>
<a class="sourceLine" id="cb41-28" title="28">        <span class="dt">void</span> <span class="fu">onClickRetry</span>();</a>
<a class="sourceLine" id="cb41-29" title="29"></a>
<a class="sourceLine" id="cb41-30" title="30">        <span class="co">/**</span></a>
<a class="sourceLine" id="cb41-31" title="31">         <span class="co">*</span> 点击查看详情或下载按钮</a>
<a class="sourceLine" id="cb41-32" title="32">         <span class="co">*/</span></a>
<a class="sourceLine" id="cb41-33" title="33">        <span class="dt">void</span> <span class="fu">onClick</span>();</a>
<a class="sourceLine" id="cb41-34" title="34">    }</a>
<a class="sourceLine" id="cb41-35" title="35"></a>
<a class="sourceLine" id="cb41-36" title="36">}</a></code></pre></div>
<p>接口中其他方法请参考TTFeedAd接口。</p>
<h4 id="加载draw竖版视频信息流广告">2.11.2 加载Draw竖版视频信息流广告</h4>
<p>接入方可调用<code>loadDrawFeedAd(AdSlot adSlot, @NonNull DrawFeedAdListener listener)</code>异步加载广告，adslot为请求广告的信息，DrawFeedAdListener为广告加载成功或失败的回调。</p>
<div class="sourceCode" id="cb42"><pre class="sourceCode java"><code class="sourceCode java"><a class="sourceLine" id="cb42-1" title="1"> <span class="co">//设置广告参数</span></a>
<a class="sourceLine" id="cb42-2" title="2">  AdSlot adSlot = <span class="kw">new</span> AdSlot.<span class="fu">Builder</span>()</a>
<a class="sourceLine" id="cb42-3" title="3">                .<span class="fu">setCodeId</span>(<span class="st">&quot;901121709&quot;</span>) <span class="co">//开发者申请的广告位</span></a>
<a class="sourceLine" id="cb42-4" title="4">                .<span class="fu">setSupportDeepLink</span>(<span class="kw">true</span>)</a>
<a class="sourceLine" id="cb42-5" title="5">                .<span class="fu">setImageAcceptedSize</span>(<span class="dv">1080</span>, <span class="dv">1920</span>) <span class="co">//符合广告场景的广告尺寸</span></a>
<a class="sourceLine" id="cb42-6" title="6">                .<span class="fu">setAdCount</span>(<span class="dv">1</span>) <span class="co">//请求广告数量为1到3条</span></a>
<a class="sourceLine" id="cb42-7" title="7">                .<span class="fu">build</span>();</a>
<a class="sourceLine" id="cb42-8" title="8">       <span class="co">//加载广告</span></a>
<a class="sourceLine" id="cb42-9" title="9">         mTTAdNative.<span class="fu">loadDrawFeedAd</span>(adSlot, <span class="kw">new</span> TTAdNative.<span class="fu">DrawFeedAdListener</span>() {</a>
<a class="sourceLine" id="cb42-10" title="10">            <span class="at">@Override</span></a>
<a class="sourceLine" id="cb42-11" title="11">            <span class="kw">public</span> <span class="dt">void</span> <span class="fu">onError</span>(<span class="dt">int</span> code, <span class="bu">String</span> message) {</a>
<a class="sourceLine" id="cb42-12" title="12">                Log.<span class="fu">d</span>(TAG, message);</a>
<a class="sourceLine" id="cb42-13" title="13">                mHasLoaded = <span class="kw">true</span>;</a>
<a class="sourceLine" id="cb42-14" title="14">                <span class="fu">showToast</span>(message);</a>
<a class="sourceLine" id="cb42-15" title="15">            }</a>
<a class="sourceLine" id="cb42-16" title="16"></a>
<a class="sourceLine" id="cb42-17" title="17">            <span class="at">@Override</span></a>
<a class="sourceLine" id="cb42-18" title="18">            <span class="kw">public</span> <span class="dt">void</span> <span class="fu">onDrawFeedAdLoad</span>(<span class="bu">List</span>&lt;TTDrawFeedAd&gt; ads) {</a>
<a class="sourceLine" id="cb42-19" title="19">                mHasLoaded = <span class="kw">true</span>;</a>
<a class="sourceLine" id="cb42-20" title="20">                <span class="kw">if</span> (ads == <span class="kw">null</span> || ads.<span class="fu">isEmpty</span>()) {</a>
<a class="sourceLine" id="cb42-21" title="21">                    TToast.<span class="fu">show</span>(NativeVerticalVideoActivity.<span class="fu">this</span>, <span class="st">&quot; ad is null!&quot;</span>);</a>
<a class="sourceLine" id="cb42-22" title="22">                    <span class="kw">return</span>;</a>
<a class="sourceLine" id="cb42-23" title="23">                }</a>
<a class="sourceLine" id="cb42-24" title="24">                <span class="co">//为广告设置activity对象，下载相关行为需要该context对象</span></a>
<a class="sourceLine" id="cb42-25" title="25">                <span class="kw">for</span> (TTDrawFeedAd ad : ads) {</a>
<a class="sourceLine" id="cb42-26" title="26">                    ad.<span class="fu">setActivityForDownloadApp</span>(NativeVerticalVideoActivity.<span class="fu">this</span>);</a>
<a class="sourceLine" id="cb42-27" title="27">                    <span class="co">//点击监听器必须在getAdView之前调</span></a>
<a class="sourceLine" id="cb42-28" title="28">                    ad.<span class="fu">setDrawVideoListener</span>(<span class="kw">new</span> TTDrawFeedAd.<span class="fu">DrawVideoListener</span>() {</a>
<a class="sourceLine" id="cb42-29" title="29">                        <span class="at">@Override</span></a>
<a class="sourceLine" id="cb42-30" title="30">                        <span class="kw">public</span> <span class="dt">void</span> <span class="fu">onClickRetry</span>() {</a>
<a class="sourceLine" id="cb42-31" title="31">                            TToast.<span class="fu">show</span>(DrawNativeVideoActivity.<span class="fu">this</span>, <span class="st">&quot; onClickRetry !&quot;</span>);</a>
<a class="sourceLine" id="cb42-32" title="32">                            Log.<span class="fu">d</span>(<span class="st">&quot;drawss&quot;</span>, <span class="st">&quot;onClickRetry!&quot;</span>);</a>
<a class="sourceLine" id="cb42-33" title="33">                        }</a>
<a class="sourceLine" id="cb42-34" title="34"></a>
<a class="sourceLine" id="cb42-35" title="35">                        <span class="at">@Override</span></a>
<a class="sourceLine" id="cb42-36" title="36">                        <span class="kw">public</span> <span class="dt">void</span> <span class="fu">onClick</span>() {</a>
<a class="sourceLine" id="cb42-37" title="37">                            Log.<span class="fu">d</span>(<span class="st">&quot;drawss&quot;</span>, <span class="st">&quot;onClick download or view detail page ! !&quot;</span>);</a>
<a class="sourceLine" id="cb42-38" title="38">                            TToast.<span class="fu">show</span>(DrawNativeVideoActivity.<span class="fu">this</span>, <span class="st">&quot; setDrawVideoListener click download or view detail page !&quot;</span>);</a>
<a class="sourceLine" id="cb42-39" title="39">                        }</a>
<a class="sourceLine" id="cb42-40" title="40">                    });</a>
<a class="sourceLine" id="cb42-41" title="41">                }</a>
<a class="sourceLine" id="cb42-42" title="42">                <span class="co">//设置广告视频区域是否响应点击行为，控制视频暂停、继续播放，默认不响应；</span></a>
<a class="sourceLine" id="cb42-43" title="43">                ads.<span class="fu">get</span>(<span class="dv">0</span>).<span class="fu">setCanInterruptVideoPlay</span>(<span class="kw">true</span>);</a>
<a class="sourceLine" id="cb42-44" title="44">                <span class="co">//设置视频暂停的Icon和大小</span></a>
<a class="sourceLine" id="cb42-45" title="45">                ads.<span class="fu">get</span>(<span class="dv">0</span>).<span class="fu">setPauseIcon</span>(BitmapFactory.<span class="fu">decodeResource</span>(mContext.<span class="fu">getResources</span>(),R.<span class="fu">drawable</span>.<span class="fu">dislike_icon</span>), <span class="dv">60</span>);</a>
<a class="sourceLine" id="cb42-46" title="46">                <span class="co">//获取广告视频播放的view并放入广告容器中</span></a>
<a class="sourceLine" id="cb42-47" title="47">                mAdContainer.<span class="fu">addView</span>(ads.<span class="fu">get</span>(<span class="dv">0</span>).<span class="fu">getAdView</span>());</a>
<a class="sourceLine" id="cb42-48" title="48">                <span class="co">//初始化并绑定广告行为</span></a>
<a class="sourceLine" id="cb42-49" title="49">                <span class="fu">initAdViewAndAction</span>(ads.<span class="fu">get</span>(<span class="dv">0</span>));</a>
<a class="sourceLine" id="cb42-50" title="50">            }</a>
<a class="sourceLine" id="cb42-51" title="51">        });</a>
<a class="sourceLine" id="cb42-52" title="52">    }</a>
<a class="sourceLine" id="cb42-53" title="53">    <span class="co">//绑定广告行为</span></a>
<a class="sourceLine" id="cb42-54" title="54">    <span class="kw">private</span> <span class="dt">void</span> <span class="fu">initAdViewAndAction</span>(TTDrawFeedAd ad){</a>
<a class="sourceLine" id="cb42-55" title="55">        <span class="bu">Button</span> action = <span class="kw">new</span> <span class="bu">Button</span>(<span class="kw">this</span>);</a>
<a class="sourceLine" id="cb42-56" title="56">        action.<span class="fu">setText</span>(ad.<span class="fu">getButtonText</span>());</a>
<a class="sourceLine" id="cb42-57" title="57">        <span class="bu">Button</span> btTitle = <span class="kw">new</span> <span class="bu">Button</span>(<span class="kw">this</span>);</a>
<a class="sourceLine" id="cb42-58" title="58">        btTitle.<span class="fu">setText</span>(ad.<span class="fu">getTitle</span>());</a>
<a class="sourceLine" id="cb42-59" title="59"></a>
<a class="sourceLine" id="cb42-60" title="60">        <span class="co">//其他代码略</span></a>
<a class="sourceLine" id="cb42-61" title="61"></a>
<a class="sourceLine" id="cb42-62" title="62">        <span class="co">//响应点击区域的设置，分为普通的区域clickViews和创意区域creativeViews</span></a>
<a class="sourceLine" id="cb42-63" title="63">        <span class="co">//clickViews中的view被点击会尝试打开广告落地页；creativeViews中的view被点击会根据广告类型</span></a>
<a class="sourceLine" id="cb42-64" title="64">        <span class="co">//响应对应行为，如下载类广告直接下载，打开落地页类广告直接打开落地页。</span></a>
<a class="sourceLine" id="cb42-65" title="65">        <span class="co">//注意：ad.getAdView()获取的view请勿放入这两个区域中。</span></a>
<a class="sourceLine" id="cb42-66" title="66">        <span class="bu">List</span>&lt;<span class="bu">View</span>&gt; clickViews = <span class="kw">new</span> <span class="bu">ArrayList</span>&lt;&gt;();</a>
<a class="sourceLine" id="cb42-67" title="67">        clickViews.<span class="fu">add</span>(btTitle);</a>
<a class="sourceLine" id="cb42-68" title="68">        <span class="bu">List</span>&lt;<span class="bu">View</span>&gt; creativeViews = <span class="kw">new</span> <span class="bu">ArrayList</span>&lt;&gt;();</a>
<a class="sourceLine" id="cb42-69" title="69">        creativeViews.<span class="fu">add</span>(action);</a>
<a class="sourceLine" id="cb42-70" title="70">        ad.<span class="fu">registerViewForInteraction</span>(mAdContainer, clickViews, creativeViews, <span class="kw">new</span> TTNativeAd.<span class="fu">AdInteractionListener</span>() {</a>
<a class="sourceLine" id="cb42-71" title="71">            <span class="at">@Override</span></a>
<a class="sourceLine" id="cb42-72" title="72">            <span class="kw">public</span> <span class="dt">void</span> <span class="fu">onAdClicked</span>(<span class="bu">View</span> view, TTNativeAd ad) {</a>
<a class="sourceLine" id="cb42-73" title="73">                <span class="fu">showToast</span>(<span class="st">&quot;onAdClicked&quot;</span>);</a>
<a class="sourceLine" id="cb42-74" title="74">            }</a>
<a class="sourceLine" id="cb42-75" title="75"></a>
<a class="sourceLine" id="cb42-76" title="76">            <span class="at">@Override</span></a>
<a class="sourceLine" id="cb42-77" title="77">            <span class="kw">public</span> <span class="dt">void</span> <span class="fu">onAdCreativeClick</span>(<span class="bu">View</span> view, TTNativeAd ad) {</a>
<a class="sourceLine" id="cb42-78" title="78">                <span class="fu">showToast</span>(<span class="st">&quot;onAdCreativeClick&quot;</span>);</a>
<a class="sourceLine" id="cb42-79" title="79">            }</a>
<a class="sourceLine" id="cb42-80" title="80"></a>
<a class="sourceLine" id="cb42-81" title="81">            <span class="at">@Override</span></a>
<a class="sourceLine" id="cb42-82" title="82">            <span class="kw">public</span> <span class="dt">void</span> <span class="fu">onAdShow</span>(TTNativeAd ad) {</a>
<a class="sourceLine" id="cb42-83" title="83">                <span class="fu">showToast</span>(<span class="st">&quot;onAdShow&quot;</span>);</a>
<a class="sourceLine" id="cb42-84" title="84">            }</a>
<a class="sourceLine" id="cb42-85" title="85">        });</a>
<a class="sourceLine" id="cb42-86" title="86"></a>
<a class="sourceLine" id="cb42-87" title="87"></a>
<a class="sourceLine" id="cb42-88" title="88">    }</a></code></pre></div>
<h4 id="展示视频广告-2">2.11.3 展示视频广告</h4>
<div class="sourceCode" id="cb43"><pre class="sourceCode java"><code class="sourceCode java"><a class="sourceLine" id="cb43-1" title="1">mAdContainer.<span class="fu">addView</span>(ads.<span class="fu">get</span>(<span class="dv">0</span>).<span class="fu">getAdView</span>());</a></code></pre></div>
<p>通过getAdView()获取广告视频部分的view放入指定容器中，接入方同时可以获取其他广告信息，比如title、buttonText等信息，自定义绘制整个广告区域，可以和自己的应用的样式风格尽可能的接近，更加原生化。</p>
<p>详细代码请参考demo中的NativeVerticalVideoActivity以及DrawNativeVideoActivity。</p>
<h3 id="接入个性化模板信息流广告ttnativeexpressad">2.12 接入个性化模板信息流广告（TTNativeExpressAd）</h3>
<p>本SDK为接入方提供个性化模板信息流广告，支持图文和视频样式，开发者不用自行对广告样式进行编辑和渲染，可直接调用相关接口获取广告view,广告样式模板以及微调后期支持开发者编辑。</p>
<h4 id="ttnativeexpressad接口说明">2.12.1 TTNativeExpressAd接口说明：</h4>
<div class="sourceCode" id="cb44"><pre class="sourceCode java"><code class="sourceCode java"><a class="sourceLine" id="cb44-1" title="1"><span class="co">/**</span></a>
<a class="sourceLine" id="cb44-2" title="2"> <span class="co">*</span> 个性化模板信息流广告实体类的操作接口</a>
<a class="sourceLine" id="cb44-3" title="3"> <span class="co">*/</span></a>
<a class="sourceLine" id="cb44-4" title="4"><span class="kw">public</span> <span class="kw">interface</span> TTNativeExpressAd {</a>
<a class="sourceLine" id="cb44-5" title="5"></a>
<a class="sourceLine" id="cb44-6" title="6">    <span class="co">/**</span></a>
<a class="sourceLine" id="cb44-7" title="7">     <span class="co">*</span> 得到个性化模板信息流广告广告view</a>
<a class="sourceLine" id="cb44-8" title="8">     <span class="co">*</span></a>
<a class="sourceLine" id="cb44-9" title="9">     <span class="co">* @</span>return</a>
<a class="sourceLine" id="cb44-10" title="10">     <span class="co">*/</span></a>
<a class="sourceLine" id="cb44-11" title="11">    <span class="bu">View</span> <span class="fu">getExpressAdView</span>();</a>
<a class="sourceLine" id="cb44-12" title="12"></a>
<a class="sourceLine" id="cb44-13" title="13">    <span class="co">/**</span></a>
<a class="sourceLine" id="cb44-14" title="14">     <span class="co">*</span> 得到原生广告图片模式</a>
<a class="sourceLine" id="cb44-15" title="15">     <span class="co">*</span></a>
<a class="sourceLine" id="cb44-16" title="16">     <span class="co">* </span><span class="an">@return </span><span class="co">3</span> 大图 <span class="co">2小</span>图 <span class="co">4</span> 组图 <span class="co">5</span> 视频 其它：未知类型</a>
<a class="sourceLine" id="cb44-17" title="17">     <span class="co">*/</span></a>
<a class="sourceLine" id="cb44-18" title="18">    <span class="dt">int</span> <span class="fu">getImageMode</span>();</a>
<a class="sourceLine" id="cb44-19" title="19"></a>
<a class="sourceLine" id="cb44-20" title="20">    <span class="co">/**</span></a>
<a class="sourceLine" id="cb44-21" title="21">     <span class="co">*</span> 获取负反馈选项数据</a>
<a class="sourceLine" id="cb44-22" title="22">     <span class="co">*</span></a>
<a class="sourceLine" id="cb44-23" title="23">     <span class="co">* @</span>return</a>
<a class="sourceLine" id="cb44-24" title="24">     <span class="co">*/</span></a>
<a class="sourceLine" id="cb44-25" title="25">    <span class="bu">List</span>&lt;FilterWord&gt; <span class="fu">getFilterWords</span>();</a>
<a class="sourceLine" id="cb44-26" title="26"></a>
<a class="sourceLine" id="cb44-27" title="27">    <span class="co">/**</span></a>
<a class="sourceLine" id="cb44-28" title="28">     <span class="co">*</span> 注册个性化模板信息流广告交互回调</a>
<a class="sourceLine" id="cb44-29" title="29">     <span class="co">*</span></a>
<a class="sourceLine" id="cb44-30" title="30">     <span class="co">* </span><span class="an">@param listener </span>监听器</a>
<a class="sourceLine" id="cb44-31" title="31">     <span class="co">*/</span></a>
<a class="sourceLine" id="cb44-32" title="32">    <span class="dt">void</span> <span class="fu">setExpressInteractionListener</span>(ExpressAdInteractionListener listener);</a>
<a class="sourceLine" id="cb44-33" title="33">    </a>
<a class="sourceLine" id="cb44-34" title="34">     <span class="co">/**</span></a>
<a class="sourceLine" id="cb44-35" title="35">      <span class="co">*</span> 注册个性化模板插屏广告交互回调</a>
<a class="sourceLine" id="cb44-36" title="36">      <span class="co">*</span></a>
<a class="sourceLine" id="cb44-37" title="37">      <span class="co">* </span><span class="an">@param listener </span>监听器</a>
<a class="sourceLine" id="cb44-38" title="38">      <span class="co">*/</span></a>
<a class="sourceLine" id="cb44-39" title="39">     <span class="dt">void</span> <span class="fu">setExpressInteractionListener</span>(AdInteractionListener listener);</a>
<a class="sourceLine" id="cb44-40" title="40"></a>
<a class="sourceLine" id="cb44-41" title="41">    <span class="co">/**</span></a>
<a class="sourceLine" id="cb44-42" title="42">     <span class="co">*</span> 注册广告的下载回调</a>
<a class="sourceLine" id="cb44-43" title="43">     <span class="co">*</span></a>
<a class="sourceLine" id="cb44-44" title="44">     <span class="co">* </span><span class="an">@param downloadListener </span>下载回调监听器</a>
<a class="sourceLine" id="cb44-45" title="45">     <span class="co">*/</span></a>
<a class="sourceLine" id="cb44-46" title="46">    <span class="dt">void</span> <span class="fu">setDownloadListener</span>(TTAppDownloadListener downloadListener);</a>
<a class="sourceLine" id="cb44-47" title="47"></a>
<a class="sourceLine" id="cb44-48" title="48">    <span class="co">/**</span></a>
<a class="sourceLine" id="cb44-49" title="49">     <span class="co">*</span> 得到广告的交互类型</a>
<a class="sourceLine" id="cb44-50" title="50">     <span class="co">*</span></a>
<a class="sourceLine" id="cb44-51" title="51">     <span class="co">* </span><span class="an">@return </span><span class="co">2在</span>浏览器内打开 （普通类型）3落地页（普通类型），<span class="co">4:</span>应用下载，5:拨打电话 <span class="co">-1</span> 未知类型</a>
<a class="sourceLine" id="cb44-52" title="52">     <span class="co">*/</span></a>
<a class="sourceLine" id="cb44-53" title="53">    <span class="dt">int</span> <span class="fu">getInteractionType</span>();</a>
<a class="sourceLine" id="cb44-54" title="54"></a>
<a class="sourceLine" id="cb44-55" title="55">    <span class="co">/**</span></a>
<a class="sourceLine" id="cb44-56" title="56">     <span class="co">*</span> 渲染个性化模板广告</a>
<a class="sourceLine" id="cb44-57" title="57">     <span class="co">*/</span></a>
<a class="sourceLine" id="cb44-58" title="58">    <span class="dt">void</span> <span class="fu">render</span>();</a>
<a class="sourceLine" id="cb44-59" title="59"></a>
<a class="sourceLine" id="cb44-60" title="60">    <span class="co">/**</span></a>
<a class="sourceLine" id="cb44-61" title="61">     <span class="co">*</span> 资源释放</a>
<a class="sourceLine" id="cb44-62" title="62">     <span class="co">*/</span></a>
<a class="sourceLine" id="cb44-63" title="63">    <span class="dt">void</span> <span class="fu">destroy</span>();</a>
<a class="sourceLine" id="cb44-64" title="64"></a>
<a class="sourceLine" id="cb44-65" title="65">    <span class="co">/**</span></a>
<a class="sourceLine" id="cb44-66" title="66">     <span class="co">*</span> 设置在个性化模板信息流广告中使用穿山甲中dislike</a>
<a class="sourceLine" id="cb44-67" title="67">     <span class="co">*</span></a>
<a class="sourceLine" id="cb44-68" title="68">     <span class="co">* </span><span class="an">@param activity </span>创建dislike的context</a>
<a class="sourceLine" id="cb44-69" title="69">     <span class="co">*</span> <span class="an">@param dislikeInteractionCallback </span>dislike选择结果回调</a>
<a class="sourceLine" id="cb44-70" title="70">     <span class="co">*/</span></a>
<a class="sourceLine" id="cb44-71" title="71">    <span class="dt">void</span> <span class="fu">setDislikeCallback</span>(Activity activity, TTAdDislike.<span class="fu">DislikeInteractionCallback</span> dislikeInteractionCallback);</a>
<a class="sourceLine" id="cb44-72" title="72"></a>
<a class="sourceLine" id="cb44-73" title="73">    <span class="co">/**</span></a>
<a class="sourceLine" id="cb44-74" title="74">     <span class="co">*</span> 自定义dislike dialog</a>
<a class="sourceLine" id="cb44-75" title="75">     <span class="co">*</span></a>
<a class="sourceLine" id="cb44-76" title="76">     <span class="co">* </span><span class="an">@param dialog </span>自定义dialog，需要由外部传入</a>
<a class="sourceLine" id="cb44-77" title="77">     <span class="co">*</span> <span class="co">@</span>return</a>
<a class="sourceLine" id="cb44-78" title="78">     <span class="co">*/</span></a>
<a class="sourceLine" id="cb44-79" title="79">    <span class="dt">void</span> <span class="fu">setDislikeDialog</span>(TTDislikeDialogAbstract dialog);</a>
<a class="sourceLine" id="cb44-80" title="80"></a>
<a class="sourceLine" id="cb44-81" title="81">    <span class="co">/**</span></a>
<a class="sourceLine" id="cb44-82" title="82">     <span class="co">*</span> 展示插屏广告</a>
<a class="sourceLine" id="cb44-83" title="83">     <span class="co">*</span></a>
<a class="sourceLine" id="cb44-84" title="84">     <span class="co">* </span><span class="an">@param activity </span>宿主activity<span class="co">,</span>用户判断宿主是否finishing</a>
<a class="sourceLine" id="cb44-85" title="85">     <span class="co">*/</span></a>
<a class="sourceLine" id="cb44-86" title="86">    <span class="at">@MainThread</span></a>
<a class="sourceLine" id="cb44-87" title="87">    <span class="dt">void</span> <span class="fu">showInteractionExpressAd</span>(Activity activity);</a>
<a class="sourceLine" id="cb44-88" title="88"></a>
<a class="sourceLine" id="cb44-89" title="89">    <span class="co">/**</span></a>
<a class="sourceLine" id="cb44-90" title="90">     <span class="co">*</span> 设置Banner广告轮播的间隔时间，如果不设置则默认不开启轮播</a>
<a class="sourceLine" id="cb44-91" title="91">     <span class="co">*</span></a>
<a class="sourceLine" id="cb44-92" title="92">     <span class="co">* </span><span class="an">@param intervalTime </span>Banner广告轮播的间隔时间，允许值在<span class="co">30</span> <span class="co">*</span> <span class="co">1000</span> <span class="co">~</span> <span class="co">120</span> <span class="co">*</span> <span class="co">1000之间</span></a>
<a class="sourceLine" id="cb44-93" title="93">     <span class="co">*/</span></a>
<a class="sourceLine" id="cb44-94" title="94">    <span class="dt">void</span> <span class="fu">setSlideIntervalTime</span>(<span class="dt">int</span> intervalTime);</a>
<a class="sourceLine" id="cb44-95" title="95">    </a>
<a class="sourceLine" id="cb44-96" title="96">     <span class="co">/**</span></a>
<a class="sourceLine" id="cb44-97" title="97">     <span class="co">*</span> 设置视频广告的回调监听</a>
<a class="sourceLine" id="cb44-98" title="98">     <span class="co">*</span></a>
<a class="sourceLine" id="cb44-99" title="99">     <span class="co">* </span><span class="an">@param videoAdListener </span> 个性化模板视频广告的监听</a>
<a class="sourceLine" id="cb44-100" title="100">     <span class="co">*/</span></a>
<a class="sourceLine" id="cb44-101" title="101">    <span class="dt">void</span> <span class="fu">setVideoAdListener</span>(ExpressVideoAdListener videoAdListener);</a>
<a class="sourceLine" id="cb44-102" title="102"></a>
<a class="sourceLine" id="cb44-103" title="103">    <span class="co">/**</span></a>
<a class="sourceLine" id="cb44-104" title="104">     <span class="co">*</span> 个性化模板广告中视频广告是否可以点击暂停、继续播放</a>
<a class="sourceLine" id="cb44-105" title="105">     <span class="co">*</span></a>
<a class="sourceLine" id="cb44-106" title="106">     <span class="co">* </span><span class="an">@param canInterruptVideoPlay</span></a>
<a class="sourceLine" id="cb44-107" title="107">     <span class="co">*/</span></a>
<a class="sourceLine" id="cb44-108" title="108">    <span class="dt">void</span> <span class="fu">setCanInterruptVideoPlay</span>(<span class="dt">boolean</span> canInterruptVideoPlay);</a>
<a class="sourceLine" id="cb44-109" title="109">    </a>
<a class="sourceLine" id="cb44-110" title="110">    <span class="co">/**</span></a>
<a class="sourceLine" id="cb44-111" title="111">     <span class="co">*</span> 广告交互监听器</a>
<a class="sourceLine" id="cb44-112" title="112">     <span class="co">*/</span></a>
<a class="sourceLine" id="cb44-113" title="113">    <span class="kw">interface</span> ExpressAdInteractionListener {</a>
<a class="sourceLine" id="cb44-114" title="114"></a>
<a class="sourceLine" id="cb44-115" title="115">        <span class="co">/**</span></a>
<a class="sourceLine" id="cb44-116" title="116">         <span class="co">*</span>广告的点击回调</a>
<a class="sourceLine" id="cb44-117" title="117">         <span class="co">* </span><span class="an">@param view </span>广告</a>
<a class="sourceLine" id="cb44-118" title="118">         <span class="co">*</span> <span class="an">@param type </span>广告的交互类型</a>
<a class="sourceLine" id="cb44-119" title="119">         <span class="co">*/</span></a>
<a class="sourceLine" id="cb44-120" title="120">        <span class="dt">void</span> <span class="fu">onAdClicked</span>(<span class="bu">View</span> view, <span class="dt">int</span> type);</a>
<a class="sourceLine" id="cb44-121" title="121"></a>
<a class="sourceLine" id="cb44-122" title="122">        <span class="co">/**</span></a>
<a class="sourceLine" id="cb44-123" title="123">         <span class="co">*</span> 广告的展示回调 每个广告仅回调一次</a>
<a class="sourceLine" id="cb44-124" title="124">         <span class="co">* </span><span class="an">@param view </span>广告view</a>
<a class="sourceLine" id="cb44-125" title="125">         <span class="co">*</span> <span class="an">@param type </span>广告的交互类型</a>
<a class="sourceLine" id="cb44-126" title="126">         <span class="co">*/</span></a>
<a class="sourceLine" id="cb44-127" title="127">        <span class="dt">void</span> <span class="fu">onAdShow</span>(<span class="bu">View</span> view, <span class="dt">int</span> type);</a>
<a class="sourceLine" id="cb44-128" title="128"></a>
<a class="sourceLine" id="cb44-129" title="129">        <span class="co">/**</span></a>
<a class="sourceLine" id="cb44-130" title="130">         <span class="co">*</span> 个性化模板渲染失败</a>
<a class="sourceLine" id="cb44-131" title="131">         <span class="co">* </span><span class="an">@param view</span></a>
<a class="sourceLine" id="cb44-132" title="132">         <span class="co">*/</span></a>
<a class="sourceLine" id="cb44-133" title="133">        <span class="dt">void</span> <span class="fu">onRenderFail</span>(<span class="bu">View</span> view, <span class="bu">String</span> msg, <span class="dt">int</span> code);</a>
<a class="sourceLine" id="cb44-134" title="134"></a>
<a class="sourceLine" id="cb44-135" title="135">        <span class="co">/**</span></a>
<a class="sourceLine" id="cb44-136" title="136">         <span class="co">*</span> 个性化模板渲染成功</a>
<a class="sourceLine" id="cb44-137" title="137">         <span class="co">* </span><span class="an">@param view</span></a>
<a class="sourceLine" id="cb44-138" title="138">         <span class="co">*</span> <span class="an">@param width </span> 返回view的宽 单位 dp</a>
<a class="sourceLine" id="cb44-139" title="139">         <span class="co">*</span> <span class="an">@param height </span>返回view的高 单位 dp</a>
<a class="sourceLine" id="cb44-140" title="140">         <span class="co">*/</span></a>
<a class="sourceLine" id="cb44-141" title="141">        <span class="dt">void</span> <span class="fu">onRenderSuccess</span>(<span class="bu">View</span> view, <span class="dt">float</span> width, <span class="dt">float</span> height);</a>
<a class="sourceLine" id="cb44-142" title="142">    }</a>
<a class="sourceLine" id="cb44-143" title="143">    </a>
<a class="sourceLine" id="cb44-144" title="144">    <span class="co">/**</span></a>
<a class="sourceLine" id="cb44-145" title="145">     <span class="co">*</span> 个性化模板插屏广告广告交互监听器</a>
<a class="sourceLine" id="cb44-146" title="146">     <span class="co">*/</span></a>
<a class="sourceLine" id="cb44-147" title="147">    <span class="kw">interface</span> AdInteractionListener <span class="kw">extends</span> ExpressAdInteractionListener {</a>
<a class="sourceLine" id="cb44-148" title="148">    </a>
<a class="sourceLine" id="cb44-149" title="149">        <span class="co">/**</span></a>
<a class="sourceLine" id="cb44-150" title="150">         <span class="co">*</span> 插屏广告消失用户回调</a>
<a class="sourceLine" id="cb44-151" title="151">         <span class="co">*/</span></a>
<a class="sourceLine" id="cb44-152" title="152">        <span class="dt">void</span> <span class="fu">onAdDismiss</span>();</a>
<a class="sourceLine" id="cb44-153" title="153">    }</a>
<a class="sourceLine" id="cb44-154" title="154">    </a>
<a class="sourceLine" id="cb44-155" title="155">    <span class="co">/**</span></a>
<a class="sourceLine" id="cb44-156" title="156">     <span class="co">*</span> 个性化模板信息流视频广告回调接口</a>
<a class="sourceLine" id="cb44-157" title="157">     <span class="co">*/</span></a>
<a class="sourceLine" id="cb44-158" title="158">    <span class="kw">interface</span> ExpressVideoAdListener {</a>
<a class="sourceLine" id="cb44-159" title="159"></a>
<a class="sourceLine" id="cb44-160" title="160">        <span class="co">/**</span></a>
<a class="sourceLine" id="cb44-161" title="161">         <span class="co">*</span> 视频广告加载成功</a>
<a class="sourceLine" id="cb44-162" title="162">         <span class="co">*/</span></a>
<a class="sourceLine" id="cb44-163" title="163">        <span class="dt">void</span> <span class="fu">onVideoLoad</span>();</a>
<a class="sourceLine" id="cb44-164" title="164"></a>
<a class="sourceLine" id="cb44-165" title="165">        <span class="co">/**</span></a>
<a class="sourceLine" id="cb44-166" title="166">         <span class="co">*</span> 视频广告加载失败（原生MediaPlayer内部提供的错误类型）</a>
<a class="sourceLine" id="cb44-167" title="167">         <span class="co">* </span><span class="an">@param errorCode </span>错误类型：</a>
<a class="sourceLine" id="cb44-168" title="168">         <span class="co">*</span>                  MEDIA_ERROR_UNKNOWN</a>
<a class="sourceLine" id="cb44-169" title="169">         <span class="co">*</span>                  MEDIA_ERROR_SERVER_DIED</a>
<a class="sourceLine" id="cb44-170" title="170">         <span class="co">*</span></a>
<a class="sourceLine" id="cb44-171" title="171">         <span class="co">*</span> <span class="an">@param extraCode </span>额外错误信息</a>
<a class="sourceLine" id="cb44-172" title="172">         <span class="co">*</span>                  MEDIA_ERROR_IO</a>
<a class="sourceLine" id="cb44-173" title="173">         <span class="co">*</span>                  MEDIA_ERROR_MALFORMED</a>
<a class="sourceLine" id="cb44-174" title="174">         <span class="co">*</span>                  MEDIA_ERROR_UNSUPPORTED</a>
<a class="sourceLine" id="cb44-175" title="175">         <span class="co">*</span>                  MEDIA_ERROR_TIMED_OUT</a>
<a class="sourceLine" id="cb44-176" title="176">         <span class="co">*</span>                  MEDIA_ERROR_SYSTEM</a>
<a class="sourceLine" id="cb44-177" title="177">         <span class="co">*</span></a>
<a class="sourceLine" id="cb44-178" title="178">         <span class="co">*/</span></a>
<a class="sourceLine" id="cb44-179" title="179">        <span class="dt">void</span> <span class="fu">onVideoError</span>(<span class="dt">int</span> errorCode, <span class="dt">int</span> extraCode);</a>
<a class="sourceLine" id="cb44-180" title="180"></a>
<a class="sourceLine" id="cb44-181" title="181">        <span class="co">/**</span></a>
<a class="sourceLine" id="cb44-182" title="182">         <span class="co">*</span> 视频广告播放回调</a>
<a class="sourceLine" id="cb44-183" title="183">         <span class="co">*/</span></a>
<a class="sourceLine" id="cb44-184" title="184">        <span class="dt">void</span> <span class="fu">onVideoAdStartPlay</span>();</a>
<a class="sourceLine" id="cb44-185" title="185"></a>
<a class="sourceLine" id="cb44-186" title="186">        <span class="co">/**</span></a>
<a class="sourceLine" id="cb44-187" title="187">         <span class="co">*</span> 视频广告暂停回调</a>
<a class="sourceLine" id="cb44-188" title="188">         <span class="co">*/</span></a>
<a class="sourceLine" id="cb44-189" title="189">        <span class="dt">void</span> <span class="fu">onVideoAdPaused</span>();</a>
<a class="sourceLine" id="cb44-190" title="190"></a>
<a class="sourceLine" id="cb44-191" title="191">        <span class="co">/**</span></a>
<a class="sourceLine" id="cb44-192" title="192">         <span class="co">*</span> 视频广告续播</a>
<a class="sourceLine" id="cb44-193" title="193">         <span class="co">*/</span></a>
<a class="sourceLine" id="cb44-194" title="194">        <span class="dt">void</span> <span class="fu">onVideoAdContinuePlay</span>();</a>
<a class="sourceLine" id="cb44-195" title="195"></a>
<a class="sourceLine" id="cb44-196" title="196">        <span class="co">/**</span></a>
<a class="sourceLine" id="cb44-197" title="197">         <span class="co">*</span> 视频播放进度</a>
<a class="sourceLine" id="cb44-198" title="198">         <span class="co">*</span></a>
<a class="sourceLine" id="cb44-199" title="199">         <span class="co">* </span><span class="an">@param current</span></a>
<a class="sourceLine" id="cb44-200" title="200">         <span class="co">*</span> <span class="an">@param duration</span></a>
<a class="sourceLine" id="cb44-201" title="201">         <span class="co">*/</span></a>
<a class="sourceLine" id="cb44-202" title="202">        <span class="dt">void</span> <span class="fu">onProgressUpdate</span>(<span class="dt">long</span> current, <span class="dt">long</span> duration);</a>
<a class="sourceLine" id="cb44-203" title="203"></a>
<a class="sourceLine" id="cb44-204" title="204">        <span class="co">/**</span></a>
<a class="sourceLine" id="cb44-205" title="205">         <span class="co">*</span> 视频广告播放完成回调</a>
<a class="sourceLine" id="cb44-206" title="206">         <span class="co">*/</span></a>
<a class="sourceLine" id="cb44-207" title="207">        <span class="dt">void</span> <span class="fu">onVideoAdComplete</span>();</a>
<a class="sourceLine" id="cb44-208" title="208"></a>
<a class="sourceLine" id="cb44-209" title="209">        <span class="co">/**</span></a>
<a class="sourceLine" id="cb44-210" title="210">         <span class="co">*</span> 点击重播</a>
<a class="sourceLine" id="cb44-211" title="211">         <span class="co">*/</span></a>
<a class="sourceLine" id="cb44-212" title="212">        <span class="dt">void</span> <span class="fu">onClickRetry</span>();</a>
<a class="sourceLine" id="cb44-213" title="213">    }</a>
<a class="sourceLine" id="cb44-214" title="214">}</a></code></pre></div>
<h4 id="加载个性化模板信息流广告绑定接口回调dislike逻辑">2.12.2 加载个性化模板信息流广告，绑定接口回调、dislike逻辑</h4>
<p>接入方可调用<code>loadNativeExpressAd(AdSlot adSlot, @NonNull NativeExpressAdListener listener)</code>异步加载广告，adslot为请求广告的信息，NativeExpressAdListener为广告加载成功或失败等回调。</p>
<p><strong>注意</strong>:期望个性化模板尺寸的参数设置中，如果高度设置为0,则高度会自适应;dislike逻辑有助于我们提升广告体验和匹配度，请按照接入说明设置，<strong>如果不设置dislike的回调则布局中的dislike逻辑不生效。</strong></p>
<div class="sourceCode" id="cb45"><pre class="sourceCode java"><code class="sourceCode java"><a class="sourceLine" id="cb45-1" title="1"> <span class="co">//设置广告参数</span></a>
<a class="sourceLine" id="cb45-2" title="2">   AdSlot adSlot = <span class="kw">new</span> AdSlot.<span class="fu">Builder</span>()</a>
<a class="sourceLine" id="cb45-3" title="3">                  .<span class="fu">setCodeId</span>(codeId) <span class="co">//广告位id</span></a>
<a class="sourceLine" id="cb45-4" title="4">                  .<span class="fu">setSupportDeepLink</span>(<span class="kw">true</span>)</a>
<a class="sourceLine" id="cb45-5" title="5">                  .<span class="fu">setAdCount</span>(<span class="dv">1</span>) <span class="co">//请求广告数量为1到3条</span></a>
<a class="sourceLine" id="cb45-6" title="6">                  .<span class="fu">setExpressViewAcceptedSize</span>(expressViewWidth,expressViewHeight) <span class="co">//期望个性化模板广告view的size,单位dp</span></a>
<a class="sourceLine" id="cb45-7" title="7">                  .<span class="fu">setImageAcceptedSize</span>(<span class="dv">640</span>,<span class="dv">320</span>) <span class="co">//这个参数设置即可，不影响个性化模板广告的size</span></a>
<a class="sourceLine" id="cb45-8" title="8">                  .<span class="fu">build</span>();</a>
<a class="sourceLine" id="cb45-9" title="9">       <span class="co">//加载广告</span></a>
<a class="sourceLine" id="cb45-10" title="10">         mTTAdNative.<span class="fu">loadNativeExpressAd</span>(adSlot, <span class="kw">new</span> TTAdNative.<span class="fu">NativeExpressAdListener</span>() {</a>
<a class="sourceLine" id="cb45-11" title="11">                     <span class="at">@Override</span></a>
<a class="sourceLine" id="cb45-12" title="12">                     <span class="kw">public</span> <span class="dt">void</span> <span class="fu">onError</span>(<span class="dt">int</span> code, <span class="bu">String</span> message) {</a>
<a class="sourceLine" id="cb45-13" title="13">                         TToast.<span class="fu">show</span>(NativeExpressActivity.<span class="fu">this</span>, <span class="st">&quot;load error : &quot;</span> + code + <span class="st">&quot;, &quot;</span> + message);</a>
<a class="sourceLine" id="cb45-14" title="14">                         mExpressContainer.<span class="fu">removeAllViews</span>();</a>
<a class="sourceLine" id="cb45-15" title="15">                     }</a>
<a class="sourceLine" id="cb45-16" title="16">         </a>
<a class="sourceLine" id="cb45-17" title="17">                     <span class="at">@Override</span></a>
<a class="sourceLine" id="cb45-18" title="18">                     <span class="kw">public</span> <span class="dt">void</span> <span class="fu">onNativeExpressAdLoad</span>(<span class="bu">List</span>&lt;TTNativeExpressAd&gt; ads) {</a>
<a class="sourceLine" id="cb45-19" title="19">                         <span class="kw">if</span> (ads == <span class="kw">null</span> || ads.<span class="fu">size</span>() == <span class="dv">0</span>){</a>
<a class="sourceLine" id="cb45-20" title="20">                             <span class="kw">return</span>;</a>
<a class="sourceLine" id="cb45-21" title="21">                         }</a>
<a class="sourceLine" id="cb45-22" title="22">                         mTTAd = ads.<span class="fu">get</span>(<span class="dv">0</span>);</a>
<a class="sourceLine" id="cb45-23" title="23">                         <span class="fu">bindAdListener</span>(mTTAd);</a>
<a class="sourceLine" id="cb45-24" title="24">                         mTTAd.<span class="fu">render</span>();<span class="co">//调用render开始渲染广告</span></a>
<a class="sourceLine" id="cb45-25" title="25">                     }</a>
<a class="sourceLine" id="cb45-26" title="26">                 });</a>
<a class="sourceLine" id="cb45-27" title="27">    <span class="co">//绑定广告行为</span></a>
<a class="sourceLine" id="cb45-28" title="28">    <span class="kw">private</span> <span class="dt">void</span> <span class="fu">bindAdListener</span>(TTNativeExpressAd ad) {</a>
<a class="sourceLine" id="cb45-29" title="29">            ad.<span class="fu">setExpressInteractionListener</span>(<span class="kw">new</span> TTNativeExpressAd.<span class="fu">ExpressAdInteractionListener</span>() {</a>
<a class="sourceLine" id="cb45-30" title="30">                <span class="at">@Override</span></a>
<a class="sourceLine" id="cb45-31" title="31">                <span class="kw">public</span> <span class="dt">void</span> <span class="fu">onAdClicked</span>(<span class="bu">View</span> view, <span class="dt">int</span> type) {</a>
<a class="sourceLine" id="cb45-32" title="32">                    TToast.<span class="fu">show</span>(mContext, <span class="st">&quot;广告被点击&quot;</span>);</a>
<a class="sourceLine" id="cb45-33" title="33">                }</a>
<a class="sourceLine" id="cb45-34" title="34">    </a>
<a class="sourceLine" id="cb45-35" title="35">                <span class="at">@Override</span></a>
<a class="sourceLine" id="cb45-36" title="36">                <span class="kw">public</span> <span class="dt">void</span> <span class="fu">onAdShow</span>(<span class="bu">View</span> view, <span class="dt">int</span> type) {</a>
<a class="sourceLine" id="cb45-37" title="37">                    TToast.<span class="fu">show</span>(mContext, <span class="st">&quot;广告展示&quot;</span>);</a>
<a class="sourceLine" id="cb45-38" title="38">                }</a>
<a class="sourceLine" id="cb45-39" title="39">    </a>
<a class="sourceLine" id="cb45-40" title="40">                <span class="at">@Override</span></a>
<a class="sourceLine" id="cb45-41" title="41">                <span class="kw">public</span> <span class="dt">void</span> <span class="fu">onRenderFail</span>(<span class="bu">View</span> view, <span class="bu">String</span> msg, <span class="dt">int</span> code) {</a>
<a class="sourceLine" id="cb45-42" title="42">                    Log.<span class="fu">e</span>(<span class="st">&quot;ExpressView&quot;</span>,<span class="st">&quot;render fail:&quot;</span>+(<span class="bu">System</span>.<span class="fu">currentTimeMillis</span>() - startTime));</a>
<a class="sourceLine" id="cb45-43" title="43">                    TToast.<span class="fu">show</span>(mContext, msg+<span class="st">&quot; code:&quot;</span>+code);</a>
<a class="sourceLine" id="cb45-44" title="44">                }</a>
<a class="sourceLine" id="cb45-45" title="45">    </a>
<a class="sourceLine" id="cb45-46" title="46">                <span class="at">@Override</span></a>
<a class="sourceLine" id="cb45-47" title="47">                <span class="kw">public</span> <span class="dt">void</span> <span class="fu">onRenderSuccess</span>(<span class="bu">View</span> view, <span class="dt">float</span> width, <span class="dt">float</span> height) {</a>
<a class="sourceLine" id="cb45-48" title="48">                    <span class="co">//返回view的宽高 单位 dp</span></a>
<a class="sourceLine" id="cb45-49" title="49">                    TToast.<span class="fu">show</span>(mContext, <span class="st">&quot;渲染成功&quot;</span>);</a>
<a class="sourceLine" id="cb45-50" title="50">                    <span class="co">//在渲染成功回调时展示广告，提升体验</span></a>
<a class="sourceLine" id="cb45-51" title="51">                    mExpressContainer.<span class="fu">removeAllViews</span>();</a>
<a class="sourceLine" id="cb45-52" title="52">                    mExpressContainer.<span class="fu">addView</span>(view);</a>
<a class="sourceLine" id="cb45-53" title="53">                }</a>
<a class="sourceLine" id="cb45-54" title="54">            });</a>
<a class="sourceLine" id="cb45-55" title="55">            <span class="co">//dislike设置</span></a>
<a class="sourceLine" id="cb45-56" title="56">            <span class="fu">bindDislike</span>(ad, <span class="kw">false</span>);</a>
<a class="sourceLine" id="cb45-57" title="57">            <span class="kw">if</span> (ad.<span class="fu">getInteractionType</span>() != TTAdConstant.<span class="fu">INTERACTION_TYPE_DOWNLOAD</span>){</a>
<a class="sourceLine" id="cb45-58" title="58">                <span class="kw">return</span>;</a>
<a class="sourceLine" id="cb45-59" title="59">            }</a>
<a class="sourceLine" id="cb45-60" title="60">            <span class="co">//可选，下载监听设置</span></a>
<a class="sourceLine" id="cb45-61" title="61">            ad.<span class="fu">setDownloadListener</span>(<span class="kw">new</span> <span class="fu">TTAppDownloadListener</span>() {</a>
<a class="sourceLine" id="cb45-62" title="62">                <span class="at">@Override</span></a>
<a class="sourceLine" id="cb45-63" title="63">                <span class="kw">public</span> <span class="dt">void</span> <span class="fu">onIdle</span>() {</a>
<a class="sourceLine" id="cb45-64" title="64">                    TToast.<span class="fu">show</span>(NativeExpressActivity.<span class="fu">this</span>, <span class="st">&quot;点击开始下载&quot;</span>, Toast.<span class="fu">LENGTH_LONG</span>);</a>
<a class="sourceLine" id="cb45-65" title="65">                }</a>
<a class="sourceLine" id="cb45-66" title="66">    </a>
<a class="sourceLine" id="cb45-67" title="67">                <span class="at">@Override</span></a>
<a class="sourceLine" id="cb45-68" title="68">                <span class="kw">public</span> <span class="dt">void</span> <span class="fu">onDownloadActive</span>(<span class="dt">long</span> totalBytes, <span class="dt">long</span> currBytes, <span class="bu">String</span> fileName, <span class="bu">String</span> appName) {</a>
<a class="sourceLine" id="cb45-69" title="69">                    <span class="kw">if</span> (!mHasShowDownloadActive) {</a>
<a class="sourceLine" id="cb45-70" title="70">                        mHasShowDownloadActive = <span class="kw">true</span>;</a>
<a class="sourceLine" id="cb45-71" title="71">                        TToast.<span class="fu">show</span>(NativeExpressActivity.<span class="fu">this</span>, <span class="st">&quot;下载中，点击暂停&quot;</span>, Toast.<span class="fu">LENGTH_LONG</span>);</a>
<a class="sourceLine" id="cb45-72" title="72">                    }</a>
<a class="sourceLine" id="cb45-73" title="73">                }</a>
<a class="sourceLine" id="cb45-74" title="74">    </a>
<a class="sourceLine" id="cb45-75" title="75">                <span class="at">@Override</span></a>
<a class="sourceLine" id="cb45-76" title="76">                <span class="kw">public</span> <span class="dt">void</span> <span class="fu">onDownloadPaused</span>(<span class="dt">long</span> totalBytes, <span class="dt">long</span> currBytes, <span class="bu">String</span> fileName, <span class="bu">String</span> appName) {</a>
<a class="sourceLine" id="cb45-77" title="77">                    TToast.<span class="fu">show</span>(NativeExpressActivity.<span class="fu">this</span>, <span class="st">&quot;下载暂停，点击继续&quot;</span>, Toast.<span class="fu">LENGTH_LONG</span>);</a>
<a class="sourceLine" id="cb45-78" title="78">                }</a>
<a class="sourceLine" id="cb45-79" title="79">    </a>
<a class="sourceLine" id="cb45-80" title="80">                <span class="at">@Override</span></a>
<a class="sourceLine" id="cb45-81" title="81">                <span class="kw">public</span> <span class="dt">void</span> <span class="fu">onDownloadFailed</span>(<span class="dt">long</span> totalBytes, <span class="dt">long</span> currBytes, <span class="bu">String</span> fileName, <span class="bu">String</span> appName) {</a>
<a class="sourceLine" id="cb45-82" title="82">                    TToast.<span class="fu">show</span>(NativeExpressActivity.<span class="fu">this</span>, <span class="st">&quot;下载失败，点击重新下载&quot;</span>, Toast.<span class="fu">LENGTH_LONG</span>);</a>
<a class="sourceLine" id="cb45-83" title="83">                }</a>
<a class="sourceLine" id="cb45-84" title="84">    </a>
<a class="sourceLine" id="cb45-85" title="85">                <span class="at">@Override</span></a>
<a class="sourceLine" id="cb45-86" title="86">                <span class="kw">public</span> <span class="dt">void</span> <span class="fu">onInstalled</span>(<span class="bu">String</span> fileName, <span class="bu">String</span> appName) {</a>
<a class="sourceLine" id="cb45-87" title="87">                    TToast.<span class="fu">show</span>(NativeExpressActivity.<span class="fu">this</span>, <span class="st">&quot;安装完成，点击图片打开&quot;</span>, Toast.<span class="fu">LENGTH_LONG</span>);</a>
<a class="sourceLine" id="cb45-88" title="88">                }</a>
<a class="sourceLine" id="cb45-89" title="89">    </a>
<a class="sourceLine" id="cb45-90" title="90">                <span class="at">@Override</span></a>
<a class="sourceLine" id="cb45-91" title="91">                <span class="kw">public</span> <span class="dt">void</span> <span class="fu">onDownloadFinished</span>(<span class="dt">long</span> totalBytes, <span class="bu">String</span> fileName, <span class="bu">String</span> appName) {</a>
<a class="sourceLine" id="cb45-92" title="92">                    TToast.<span class="fu">show</span>(NativeExpressActivity.<span class="fu">this</span>, <span class="st">&quot;点击安装&quot;</span>, Toast.<span class="fu">LENGTH_LONG</span>);</a>
<a class="sourceLine" id="cb45-93" title="93">                }</a>
<a class="sourceLine" id="cb45-94" title="94">            });</a>
<a class="sourceLine" id="cb45-95" title="95">        }</a>
<a class="sourceLine" id="cb45-96" title="96">        <span class="co">/**</span></a>
<a class="sourceLine" id="cb45-97" title="97">         <span class="co">*</span> 设置广告的不喜欢，开发者可自定义样式</a>
<a class="sourceLine" id="cb45-98" title="98">         <span class="co">* </span><span class="an">@param ad</span></a>
<a class="sourceLine" id="cb45-99" title="99">         <span class="co">*</span> <span class="an">@param customStyle </span>是否自定义样式，true<span class="co">:</span>样式自定义</a>
<a class="sourceLine" id="cb45-100" title="100">         <span class="co">*/</span></a>
<a class="sourceLine" id="cb45-101" title="101">        <span class="kw">private</span> <span class="dt">void</span> <span class="fu">bindDislike</span>(TTNativeExpressAd ad, <span class="dt">boolean</span> customStyle) {</a>
<a class="sourceLine" id="cb45-102" title="102">            <span class="kw">if</span> (customStyle) {</a>
<a class="sourceLine" id="cb45-103" title="103">                <span class="co">//使用自定义样式</span></a>
<a class="sourceLine" id="cb45-104" title="104">                <span class="bu">List</span>&lt;FilterWord&gt; words = ad.<span class="fu">getFilterWords</span>();</a>
<a class="sourceLine" id="cb45-105" title="105">                <span class="kw">if</span> (words == <span class="kw">null</span> || words.<span class="fu">isEmpty</span>()) {</a>
<a class="sourceLine" id="cb45-106" title="106">                    <span class="kw">return</span>;</a>
<a class="sourceLine" id="cb45-107" title="107">                }</a>
<a class="sourceLine" id="cb45-108" title="108">        </a>
<a class="sourceLine" id="cb45-109" title="109">                <span class="dt">final</span> DislikeDialog dislikeDialog = <span class="kw">new</span> <span class="fu">DislikeDialog</span>(<span class="kw">this</span>, words);</a>
<a class="sourceLine" id="cb45-110" title="110">                dislikeDialog.<span class="fu">setOnDislikeItemClick</span>(<span class="kw">new</span> DislikeDialog.<span class="fu">OnDislikeItemClick</span>() {</a>
<a class="sourceLine" id="cb45-111" title="111">                    <span class="at">@Override</span></a>
<a class="sourceLine" id="cb45-112" title="112">                    <span class="kw">public</span> <span class="dt">void</span> <span class="fu">onItemClick</span>(FilterWord filterWord) {</a>
<a class="sourceLine" id="cb45-113" title="113">                        <span class="co">//屏蔽广告</span></a>
<a class="sourceLine" id="cb45-114" title="114">                        TToast.<span class="fu">show</span>(mContext, <span class="st">&quot;点击 &quot;</span> + filterWord.<span class="fu">getName</span>());</a>
<a class="sourceLine" id="cb45-115" title="115">                        <span class="co">//用户选择不喜欢原因后，移除广告展示</span></a>
<a class="sourceLine" id="cb45-116" title="116">                        mExpressContainer.<span class="fu">removeAllViews</span>();</a>
<a class="sourceLine" id="cb45-117" title="117">                    }</a>
<a class="sourceLine" id="cb45-118" title="118">                });</a>
<a class="sourceLine" id="cb45-119" title="119">                ad.<span class="fu">setDislikeDialog</span>(dislikeDialog);</a>
<a class="sourceLine" id="cb45-120" title="120">                <span class="kw">return</span>;</a>
<a class="sourceLine" id="cb45-121" title="121">            }</a>
<a class="sourceLine" id="cb45-122" title="122">            <span class="co">//使用默认个性化模板中默认dislike弹出样式</span></a>
<a class="sourceLine" id="cb45-123" title="123">            ad.<span class="fu">setDislikeCallback</span>(NativeExpressActivity.<span class="fu">this</span>, <span class="kw">new</span> TTAdDislike.<span class="fu">DislikeInteractionCallback</span>() {</a>
<a class="sourceLine" id="cb45-124" title="124">                <span class="at">@Override</span></a>
<a class="sourceLine" id="cb45-125" title="125">                <span class="kw">public</span> <span class="dt">void</span> <span class="fu">onSelected</span>(<span class="dt">int</span> position, <span class="bu">String</span> value) {</a>
<a class="sourceLine" id="cb45-126" title="126">                    TToast.<span class="fu">show</span>(mContext, <span class="st">&quot;点击 &quot;</span> + value);</a>
<a class="sourceLine" id="cb45-127" title="127">                    <span class="co">//用户选择不喜欢原因后，移除广告展示</span></a>
<a class="sourceLine" id="cb45-128" title="128">                    mExpressContainer.<span class="fu">removeAllViews</span>();</a>
<a class="sourceLine" id="cb45-129" title="129">                }</a>
<a class="sourceLine" id="cb45-130" title="130">        </a>
<a class="sourceLine" id="cb45-131" title="131">                <span class="at">@Override</span></a>
<a class="sourceLine" id="cb45-132" title="132">                <span class="kw">public</span> <span class="dt">void</span> <span class="fu">onCancel</span>() {</a>
<a class="sourceLine" id="cb45-133" title="133">                    TToast.<span class="fu">show</span>(mContext, <span class="st">&quot;点击取消 &quot;</span>);</a>
<a class="sourceLine" id="cb45-134" title="134">                }</a>
<a class="sourceLine" id="cb45-135" title="135">            });</a>
<a class="sourceLine" id="cb45-136" title="136">        }</a>
<a class="sourceLine" id="cb45-137" title="137">        </a>
<a class="sourceLine" id="cb45-138" title="138">        <span class="co">//在合适的时机，释放广告的资源</span></a>
<a class="sourceLine" id="cb45-139" title="139">        <span class="at">@Override</span></a>
<a class="sourceLine" id="cb45-140" title="140">        <span class="kw">protected</span> <span class="dt">void</span> <span class="fu">onDestroy</span>() {</a>
<a class="sourceLine" id="cb45-141" title="141">            <span class="kw">super</span>.<span class="fu">onDestroy</span>();</a>
<a class="sourceLine" id="cb45-142" title="142">            <span class="kw">if</span> (mTTAd != <span class="kw">null</span>) {</a>
<a class="sourceLine" id="cb45-143" title="143">                <span class="co">//调用destroy()方法释放</span></a>
<a class="sourceLine" id="cb45-144" title="144">                mTTAd.<span class="fu">destroy</span>();</a>
<a class="sourceLine" id="cb45-145" title="145">            }</a>
<a class="sourceLine" id="cb45-146" title="146">        }</a></code></pre></div>
<h4 id="展示个性化模板信息流广告">2.12.3 展示个性化模板信息流广告</h4>
<div class="sourceCode" id="cb46"><pre class="sourceCode java"><code class="sourceCode java"><a class="sourceLine" id="cb46-1" title="1"> <span class="kw">public</span> <span class="dt">void</span> <span class="fu">onRenderSuccess</span>(<span class="bu">View</span> view, <span class="dt">float</span> width, <span class="dt">float</span> height) {</a>
<a class="sourceLine" id="cb46-2" title="2">                    <span class="co">//返回view的宽高 单位 dp</span></a>
<a class="sourceLine" id="cb46-3" title="3">                    TToast.<span class="fu">show</span>(mContext, <span class="st">&quot;渲染成功&quot;</span>);</a>
<a class="sourceLine" id="cb46-4" title="4">                    <span class="co">//在渲染成功回调时展示广告，提升体验</span></a>
<a class="sourceLine" id="cb46-5" title="5">                    mExpressContainer.<span class="fu">removeAllViews</span>();</a>
<a class="sourceLine" id="cb46-6" title="6">                    mExpressContainer.<span class="fu">addView</span>(view);</a>
<a class="sourceLine" id="cb46-7" title="7">                }</a></code></pre></div>
<p>加载到广告后，调用TTNativeExpressAd.render()方法渲染广告，在onRenderSuccess(View view, float width, float height)方法 中，获取渲染成功后的广告view并添加到容器中展示。 详细代码请参考demo中的NativeExpressActivity，如果在信息流场景使用参考NativeExpressListActivity。</p>
<h3 id="接入个性化模板banner广告接口同-ttnativeexpressad">2.13 接入个性化模板Banner广告（接口同 TTNativeExpressAd）</h3>
<p>本SDK为接入方提供个性化模板Banner广告，开发者不用自行对广告样式进行编辑和渲染，可直接调用相关接口获取广告view,广告样式模板以及微调后期支持开发者编辑。</p>
<h4 id="加载个性化模板banner广告绑定接口回调dislike逻辑">2.13.1 加载个性化模板Banner广告，绑定接口回调、dislike逻辑</h4>
<p>接入方可调用<code>loadBannerExpressAd(AdSlot adSlot, @NonNull NativeExpressAdListener listener)</code>异步加载广告，adslot为请求广告的信息，NativeExpressAdListener为广告加载成功或失败等回调。</p>
<p><strong>注意</strong>:期望个性化模板尺寸的参数设置中，如果高度设置为0,则高度会自适应,尺寸大小请保持和平台设置一致；dislike逻辑有助于我们提升广告体验和匹配度，请按照接入说明设置，<strong>如果不设置dislike的回调则布局中的dislike逻辑不生效。</strong></p>
<div class="sourceCode" id="cb47"><pre class="sourceCode java"><code class="sourceCode java"><a class="sourceLine" id="cb47-1" title="1"> <span class="co">//设置广告参数</span></a>
<a class="sourceLine" id="cb47-2" title="2">   AdSlot adSlot = <span class="kw">new</span> AdSlot.<span class="fu">Builder</span>()</a>
<a class="sourceLine" id="cb47-3" title="3">                  .<span class="fu">setCodeId</span>(codeId) <span class="co">//广告位id</span></a>
<a class="sourceLine" id="cb47-4" title="4">                  .<span class="fu">setSupportDeepLink</span>(<span class="kw">true</span>)</a>
<a class="sourceLine" id="cb47-5" title="5">                  .<span class="fu">setAdCount</span>(<span class="dv">1</span>) <span class="co">//请求广告数量为1到3条</span></a>
<a class="sourceLine" id="cb47-6" title="6">                  .<span class="fu">setExpressViewAcceptedSize</span>(expressViewWidth,expressViewHeight) <span class="co">//期望个性化模板广告view的size,单位dp</span></a>
<a class="sourceLine" id="cb47-7" title="7">                  .<span class="fu">setImageAcceptedSize</span>(<span class="dv">640</span>,<span class="dv">320</span> )<span class="co">//这个参数设置即可，不影响个性化模板广告的size</span></a>
<a class="sourceLine" id="cb47-8" title="8">                  .<span class="fu">build</span>();</a>
<a class="sourceLine" id="cb47-9" title="9">       <span class="co">//加载广告</span></a>
<a class="sourceLine" id="cb47-10" title="10">         mTTAdNative.<span class="fu">loadBannerExpressAd</span>(adSlot, <span class="kw">new</span> TTAdNative.<span class="fu">NativeExpressAdListener</span>() {</a>
<a class="sourceLine" id="cb47-11" title="11">                     <span class="at">@Override</span></a>
<a class="sourceLine" id="cb47-12" title="12">                     <span class="kw">public</span> <span class="dt">void</span> <span class="fu">onError</span>(<span class="dt">int</span> code, <span class="bu">String</span> message) {</a>
<a class="sourceLine" id="cb47-13" title="13">                         TToast.<span class="fu">show</span>(NativeExpressActivity.<span class="fu">this</span>, <span class="st">&quot;load error : &quot;</span> + code + <span class="st">&quot;, &quot;</span> + message);</a>
<a class="sourceLine" id="cb47-14" title="14">                         mExpressContainer.<span class="fu">removeAllViews</span>();</a>
<a class="sourceLine" id="cb47-15" title="15">                     }</a>
<a class="sourceLine" id="cb47-16" title="16">         </a>
<a class="sourceLine" id="cb47-17" title="17">                     <span class="at">@Override</span></a>
<a class="sourceLine" id="cb47-18" title="18">                     <span class="kw">public</span> <span class="dt">void</span> <span class="fu">onNativeExpressAdLoad</span>(<span class="bu">List</span>&lt;TTNativeExpressAd&gt; ads) {</a>
<a class="sourceLine" id="cb47-19" title="19">                         <span class="kw">if</span> (ads == <span class="kw">null</span> || ads.<span class="fu">size</span>() == <span class="dv">0</span>){</a>
<a class="sourceLine" id="cb47-20" title="20">                             <span class="kw">return</span>;</a>
<a class="sourceLine" id="cb47-21" title="21">                         }</a>
<a class="sourceLine" id="cb47-22" title="22">                         mTTAd = ads.<span class="fu">get</span>(<span class="dv">0</span>);</a>
<a class="sourceLine" id="cb47-23" title="23">                         mTTAd.<span class="fu">setSlideIntervalTime</span>(<span class="dv">30</span>*<span class="dv">1000</span>);<span class="co">//设置轮播间隔 ms,不调用则不进行轮播展示</span></a>
<a class="sourceLine" id="cb47-24" title="24">                         <span class="fu">bindAdListener</span>(mTTAd);</a>
<a class="sourceLine" id="cb47-25" title="25">                         mTTAd.<span class="fu">render</span>();<span class="co">//调用render开始渲染广告</span></a>
<a class="sourceLine" id="cb47-26" title="26">                     }</a>
<a class="sourceLine" id="cb47-27" title="27">                 });</a>
<a class="sourceLine" id="cb47-28" title="28">    <span class="co">//绑定广告行为</span></a>
<a class="sourceLine" id="cb47-29" title="29">    <span class="kw">private</span> <span class="dt">void</span> <span class="fu">bindAdListener</span>(TTNativeExpressAd ad) {</a>
<a class="sourceLine" id="cb47-30" title="30">            ad.<span class="fu">setExpressInteractionListener</span>(<span class="kw">new</span> TTNativeExpressAd.<span class="fu">ExpressAdInteractionListener</span>() {</a>
<a class="sourceLine" id="cb47-31" title="31">                <span class="at">@Override</span></a>
<a class="sourceLine" id="cb47-32" title="32">                <span class="kw">public</span> <span class="dt">void</span> <span class="fu">onAdClicked</span>(<span class="bu">View</span> view, <span class="dt">int</span> type) {</a>
<a class="sourceLine" id="cb47-33" title="33">                    TToast.<span class="fu">show</span>(mContext, <span class="st">&quot;广告被点击&quot;</span>);</a>
<a class="sourceLine" id="cb47-34" title="34">                }</a>
<a class="sourceLine" id="cb47-35" title="35">    </a>
<a class="sourceLine" id="cb47-36" title="36">                <span class="at">@Override</span></a>
<a class="sourceLine" id="cb47-37" title="37">                <span class="kw">public</span> <span class="dt">void</span> <span class="fu">onAdShow</span>(<span class="bu">View</span> view, <span class="dt">int</span> type) {</a>
<a class="sourceLine" id="cb47-38" title="38">                    TToast.<span class="fu">show</span>(mContext, <span class="st">&quot;广告展示&quot;</span>);</a>
<a class="sourceLine" id="cb47-39" title="39">                }</a>
<a class="sourceLine" id="cb47-40" title="40">    </a>
<a class="sourceLine" id="cb47-41" title="41">                <span class="at">@Override</span></a>
<a class="sourceLine" id="cb47-42" title="42">                <span class="kw">public</span> <span class="dt">void</span> <span class="fu">onRenderFail</span>(<span class="bu">View</span> view, <span class="bu">String</span> msg, <span class="dt">int</span> code) {</a>
<a class="sourceLine" id="cb47-43" title="43">                    Log.<span class="fu">e</span>(<span class="st">&quot;ExpressView&quot;</span>,<span class="st">&quot;render fail:&quot;</span>+(<span class="bu">System</span>.<span class="fu">currentTimeMillis</span>() - startTime));</a>
<a class="sourceLine" id="cb47-44" title="44">                    TToast.<span class="fu">show</span>(mContext, msg+<span class="st">&quot; code:&quot;</span>+code);</a>
<a class="sourceLine" id="cb47-45" title="45">                }</a>
<a class="sourceLine" id="cb47-46" title="46">    </a>
<a class="sourceLine" id="cb47-47" title="47">                <span class="at">@Override</span></a>
<a class="sourceLine" id="cb47-48" title="48">                <span class="kw">public</span> <span class="dt">void</span> <span class="fu">onRenderSuccess</span>(<span class="bu">View</span> view, <span class="dt">float</span> width, <span class="dt">float</span> height) {</a>
<a class="sourceLine" id="cb47-49" title="49">                    <span class="co">//返回view的宽高 单位 dp</span></a>
<a class="sourceLine" id="cb47-50" title="50">                    TToast.<span class="fu">show</span>(mContext, <span class="st">&quot;渲染成功&quot;</span>);</a>
<a class="sourceLine" id="cb47-51" title="51">                    <span class="co">//在渲染成功回调时展示广告，提升体验</span></a>
<a class="sourceLine" id="cb47-52" title="52">                    mExpressContainer.<span class="fu">removeAllViews</span>();</a>
<a class="sourceLine" id="cb47-53" title="53">                    mExpressContainer.<span class="fu">addView</span>(view);</a>
<a class="sourceLine" id="cb47-54" title="54">                }</a>
<a class="sourceLine" id="cb47-55" title="55">            });</a>
<a class="sourceLine" id="cb47-56" title="56">            <span class="co">//dislike设置</span></a>
<a class="sourceLine" id="cb47-57" title="57">            <span class="fu">bindDislike</span>(ad, <span class="kw">false</span>);</a>
<a class="sourceLine" id="cb47-58" title="58">            <span class="kw">if</span> (ad.<span class="fu">getInteractionType</span>() != TTAdConstant.<span class="fu">INTERACTION_TYPE_DOWNLOAD</span>){</a>
<a class="sourceLine" id="cb47-59" title="59">                <span class="kw">return</span>;</a>
<a class="sourceLine" id="cb47-60" title="60">            }</a>
<a class="sourceLine" id="cb47-61" title="61">            <span class="co">//可选，下载监听设置</span></a>
<a class="sourceLine" id="cb47-62" title="62">            ad.<span class="fu">setDownloadListener</span>(<span class="kw">new</span> <span class="fu">TTAppDownloadListener</span>() {</a>
<a class="sourceLine" id="cb47-63" title="63">                <span class="at">@Override</span></a>
<a class="sourceLine" id="cb47-64" title="64">                <span class="kw">public</span> <span class="dt">void</span> <span class="fu">onIdle</span>() {</a>
<a class="sourceLine" id="cb47-65" title="65">                    TToast.<span class="fu">show</span>(BannerExpressActivity.<span class="fu">this</span>, <span class="st">&quot;点击开始下载&quot;</span>, Toast.<span class="fu">LENGTH_LONG</span>);</a>
<a class="sourceLine" id="cb47-66" title="66">                }</a>
<a class="sourceLine" id="cb47-67" title="67">    </a>
<a class="sourceLine" id="cb47-68" title="68">                <span class="at">@Override</span></a>
<a class="sourceLine" id="cb47-69" title="69">                <span class="kw">public</span> <span class="dt">void</span> <span class="fu">onDownloadActive</span>(<span class="dt">long</span> totalBytes, <span class="dt">long</span> currBytes, <span class="bu">String</span> fileName, <span class="bu">String</span> appName) {</a>
<a class="sourceLine" id="cb47-70" title="70">                    <span class="kw">if</span> (!mHasShowDownloadActive) {</a>
<a class="sourceLine" id="cb47-71" title="71">                        mHasShowDownloadActive = <span class="kw">true</span>;</a>
<a class="sourceLine" id="cb47-72" title="72">                        TToast.<span class="fu">show</span>(BannerExpressActivity.<span class="fu">this</span>, <span class="st">&quot;下载中，点击暂停&quot;</span>, Toast.<span class="fu">LENGTH_LONG</span>);</a>
<a class="sourceLine" id="cb47-73" title="73">                    }</a>
<a class="sourceLine" id="cb47-74" title="74">                }</a>
<a class="sourceLine" id="cb47-75" title="75">    </a>
<a class="sourceLine" id="cb47-76" title="76">                <span class="at">@Override</span></a>
<a class="sourceLine" id="cb47-77" title="77">                <span class="kw">public</span> <span class="dt">void</span> <span class="fu">onDownloadPaused</span>(<span class="dt">long</span> totalBytes, <span class="dt">long</span> currBytes, <span class="bu">String</span> fileName, <span class="bu">String</span> appName) {</a>
<a class="sourceLine" id="cb47-78" title="78">                    TToast.<span class="fu">show</span>(BannerExpressActivity.<span class="fu">this</span>, <span class="st">&quot;下载暂停，点击继续&quot;</span>, Toast.<span class="fu">LENGTH_LONG</span>);</a>
<a class="sourceLine" id="cb47-79" title="79">                }</a>
<a class="sourceLine" id="cb47-80" title="80">    </a>
<a class="sourceLine" id="cb47-81" title="81">                <span class="at">@Override</span></a>
<a class="sourceLine" id="cb47-82" title="82">                <span class="kw">public</span> <span class="dt">void</span> <span class="fu">onDownloadFailed</span>(<span class="dt">long</span> totalBytes, <span class="dt">long</span> currBytes, <span class="bu">String</span> fileName, <span class="bu">String</span> appName) {</a>
<a class="sourceLine" id="cb47-83" title="83">                    TToast.<span class="fu">show</span>(BannerExpressActivity.<span class="fu">this</span>, <span class="st">&quot;下载失败，点击重新下载&quot;</span>, Toast.<span class="fu">LENGTH_LONG</span>);</a>
<a class="sourceLine" id="cb47-84" title="84">                }</a>
<a class="sourceLine" id="cb47-85" title="85">    </a>
<a class="sourceLine" id="cb47-86" title="86">                <span class="at">@Override</span></a>
<a class="sourceLine" id="cb47-87" title="87">                <span class="kw">public</span> <span class="dt">void</span> <span class="fu">onInstalled</span>(<span class="bu">String</span> fileName, <span class="bu">String</span> appName) {</a>
<a class="sourceLine" id="cb47-88" title="88">                    TToast.<span class="fu">show</span>(BannerExpressActivity.<span class="fu">this</span>, <span class="st">&quot;安装完成，点击图片打开&quot;</span>, Toast.<span class="fu">LENGTH_LONG</span>);</a>
<a class="sourceLine" id="cb47-89" title="89">                }</a>
<a class="sourceLine" id="cb47-90" title="90">    </a>
<a class="sourceLine" id="cb47-91" title="91">                <span class="at">@Override</span></a>
<a class="sourceLine" id="cb47-92" title="92">                <span class="kw">public</span> <span class="dt">void</span> <span class="fu">onDownloadFinished</span>(<span class="dt">long</span> totalBytes, <span class="bu">String</span> fileName, <span class="bu">String</span> appName) {</a>
<a class="sourceLine" id="cb47-93" title="93">                    TToast.<span class="fu">show</span>(BannerExpressActivity.<span class="fu">this</span>, <span class="st">&quot;点击安装&quot;</span>, Toast.<span class="fu">LENGTH_LONG</span>);</a>
<a class="sourceLine" id="cb47-94" title="94">                }</a>
<a class="sourceLine" id="cb47-95" title="95">            });</a>
<a class="sourceLine" id="cb47-96" title="96">        }</a>
<a class="sourceLine" id="cb47-97" title="97">        <span class="co">/**</span></a>
<a class="sourceLine" id="cb47-98" title="98">         <span class="co">*</span> 设置广告的不喜欢，开发者可自定义样式</a>
<a class="sourceLine" id="cb47-99" title="99">         <span class="co">* </span><span class="an">@param ad</span></a>
<a class="sourceLine" id="cb47-100" title="100">         <span class="co">*</span> <span class="an">@param customStyle </span>是否自定义样式，true<span class="co">:</span>样式自定义</a>
<a class="sourceLine" id="cb47-101" title="101">         <span class="co">*/</span></a>
<a class="sourceLine" id="cb47-102" title="102">        <span class="kw">private</span> <span class="dt">void</span> <span class="fu">bindDislike</span>(TTNativeExpressAd ad, <span class="dt">boolean</span> customStyle) {</a>
<a class="sourceLine" id="cb47-103" title="103">            <span class="kw">if</span> (customStyle) {</a>
<a class="sourceLine" id="cb47-104" title="104">                <span class="co">//使用自定义样式</span></a>
<a class="sourceLine" id="cb47-105" title="105">                <span class="bu">List</span>&lt;FilterWord&gt; words = ad.<span class="fu">getFilterWords</span>();</a>
<a class="sourceLine" id="cb47-106" title="106">                <span class="kw">if</span> (words == <span class="kw">null</span> || words.<span class="fu">isEmpty</span>()) {</a>
<a class="sourceLine" id="cb47-107" title="107">                    <span class="kw">return</span>;</a>
<a class="sourceLine" id="cb47-108" title="108">                }</a>
<a class="sourceLine" id="cb47-109" title="109">        </a>
<a class="sourceLine" id="cb47-110" title="110">                <span class="dt">final</span> DislikeDialog dislikeDialog = <span class="kw">new</span> <span class="fu">DislikeDialog</span>(<span class="kw">this</span>, words);</a>
<a class="sourceLine" id="cb47-111" title="111">                dislikeDialog.<span class="fu">setOnDislikeItemClick</span>(<span class="kw">new</span> DislikeDialog.<span class="fu">OnDislikeItemClick</span>() {</a>
<a class="sourceLine" id="cb47-112" title="112">                    <span class="at">@Override</span></a>
<a class="sourceLine" id="cb47-113" title="113">                    <span class="kw">public</span> <span class="dt">void</span> <span class="fu">onItemClick</span>(FilterWord filterWord) {</a>
<a class="sourceLine" id="cb47-114" title="114">                        <span class="co">//屏蔽广告</span></a>
<a class="sourceLine" id="cb47-115" title="115">                        TToast.<span class="fu">show</span>(mContext, <span class="st">&quot;点击 &quot;</span> + filterWord.<span class="fu">getName</span>());</a>
<a class="sourceLine" id="cb47-116" title="116">                        <span class="co">//用户选择不喜欢原因后，移除广告展示</span></a>
<a class="sourceLine" id="cb47-117" title="117">                        mExpressContainer.<span class="fu">removeAllViews</span>();</a>
<a class="sourceLine" id="cb47-118" title="118">                    }</a>
<a class="sourceLine" id="cb47-119" title="119">                });</a>
<a class="sourceLine" id="cb47-120" title="120">                ad.<span class="fu">setDislikeDialog</span>(dislikeDialog);</a>
<a class="sourceLine" id="cb47-121" title="121">                <span class="kw">return</span>;</a>
<a class="sourceLine" id="cb47-122" title="122">            }</a>
<a class="sourceLine" id="cb47-123" title="123">            <span class="co">//使用默认个性化模板中默认dislike弹出样式</span></a>
<a class="sourceLine" id="cb47-124" title="124">            ad.<span class="fu">setDislikeCallback</span>(BannerExpressActivity.<span class="fu">this</span>, <span class="kw">new</span> TTAdDislike.<span class="fu">DislikeInteractionCallback</span>() {</a>
<a class="sourceLine" id="cb47-125" title="125">                <span class="at">@Override</span></a>
<a class="sourceLine" id="cb47-126" title="126">                <span class="kw">public</span> <span class="dt">void</span> <span class="fu">onSelected</span>(<span class="dt">int</span> position, <span class="bu">String</span> value) {</a>
<a class="sourceLine" id="cb47-127" title="127">                    TToast.<span class="fu">show</span>(mContext, <span class="st">&quot;点击 &quot;</span> + value);</a>
<a class="sourceLine" id="cb47-128" title="128">                    <span class="co">//用户选择不喜欢原因后，移除广告展示</span></a>
<a class="sourceLine" id="cb47-129" title="129">                    mExpressContainer.<span class="fu">removeAllViews</span>();</a>
<a class="sourceLine" id="cb47-130" title="130">                }</a>
<a class="sourceLine" id="cb47-131" title="131">        </a>
<a class="sourceLine" id="cb47-132" title="132">                <span class="at">@Override</span></a>
<a class="sourceLine" id="cb47-133" title="133">                <span class="kw">public</span> <span class="dt">void</span> <span class="fu">onCancel</span>() {</a>
<a class="sourceLine" id="cb47-134" title="134">                    TToast.<span class="fu">show</span>(mContext, <span class="st">&quot;点击取消 &quot;</span>);</a>
<a class="sourceLine" id="cb47-135" title="135">                }</a>
<a class="sourceLine" id="cb47-136" title="136">            });</a>
<a class="sourceLine" id="cb47-137" title="137">        }</a>
<a class="sourceLine" id="cb47-138" title="138">        </a>
<a class="sourceLine" id="cb47-139" title="139">        <span class="co">//在合适的时机，释放广告的资源</span></a>
<a class="sourceLine" id="cb47-140" title="140">        <span class="at">@Override</span></a>
<a class="sourceLine" id="cb47-141" title="141">        <span class="kw">protected</span> <span class="dt">void</span> <span class="fu">onDestroy</span>() {</a>
<a class="sourceLine" id="cb47-142" title="142">            <span class="kw">super</span>.<span class="fu">onDestroy</span>();</a>
<a class="sourceLine" id="cb47-143" title="143">            <span class="kw">if</span> (mTTAd != <span class="kw">null</span>) {</a>
<a class="sourceLine" id="cb47-144" title="144">                <span class="co">//调用destroy()方法释放</span></a>
<a class="sourceLine" id="cb47-145" title="145">                mTTAd.<span class="fu">destroy</span>();</a>
<a class="sourceLine" id="cb47-146" title="146">            }</a>
<a class="sourceLine" id="cb47-147" title="147">        }</a></code></pre></div>
<h4 id="展示个性化模板banner广告">2.13.2 展示个性化模板Banner广告</h4>
<div class="sourceCode" id="cb48"><pre class="sourceCode java"><code class="sourceCode java"><a class="sourceLine" id="cb48-1" title="1"> <span class="kw">public</span> <span class="dt">void</span> <span class="fu">onRenderSuccess</span>(<span class="bu">View</span> view, <span class="dt">float</span> width, <span class="dt">float</span> height) {</a>
<a class="sourceLine" id="cb48-2" title="2">                    <span class="co">//返回view的宽高 单位 dp</span></a>
<a class="sourceLine" id="cb48-3" title="3">                    TToast.<span class="fu">show</span>(mContext, <span class="st">&quot;渲染成功&quot;</span>);</a>
<a class="sourceLine" id="cb48-4" title="4">                    <span class="co">//在渲染成功回调时展示广告，提升体验</span></a>
<a class="sourceLine" id="cb48-5" title="5">                    mExpressContainer.<span class="fu">removeAllViews</span>();</a>
<a class="sourceLine" id="cb48-6" title="6">                    mExpressContainer.<span class="fu">addView</span>(view);</a>
<a class="sourceLine" id="cb48-7" title="7">                }</a></code></pre></div>
<p>加载到广告后，调用TTNativeExpressAd.render()方法渲染广告，在onRenderSuccess(View view, float width, float height)方法 中，获取渲染成功后的广告view并添加到容器中展示。 详细代码请参考demo中的BannerExpressActivity使用示例。</p>
<h3 id="接入个性化模板插屏广告接口同-ttnativeexpressad">2.14 接入个性化模板插屏广告（接口同 TTNativeExpressAd）</h3>
<p>本SDK为接入方提供个性化模板插屏广告，开发者不用自行对广告样式进行编辑和渲染，可直接调用相关接口获取广告view,广告样式模板以及微调后期支持开发者编辑。</p>
<h4 id="加载个性化模板插屏广告绑定接口回调">2.14.1 加载个性化模板插屏广告，绑定接口回调</h4>
<p>接入方可调用<code>loadInteractionExpressAd(AdSlot adSlot, @NonNull NativeExpressAdListener listener)</code>异步加载广告，adslot为请求广告的信息，NativeExpressAdListener为广告加载成功或失败等回调。</p>
<p><strong>注意</strong>:期望个性化模板尺寸的参数设置中，如果高度设置为0,则高度会自适应,尺寸大小请保持和平台设置一致;<strong>插屏广告不支持dislike逻辑。</strong></p>
<div class="sourceCode" id="cb49"><pre class="sourceCode java"><code class="sourceCode java"><a class="sourceLine" id="cb49-1" title="1"> <span class="co">//设置广告参数</span></a>
<a class="sourceLine" id="cb49-2" title="2">   AdSlot adSlot = <span class="kw">new</span> AdSlot.<span class="fu">Builder</span>()</a>
<a class="sourceLine" id="cb49-3" title="3">                  .<span class="fu">setCodeId</span>(codeId) <span class="co">//广告位id</span></a>
<a class="sourceLine" id="cb49-4" title="4">                  .<span class="fu">setSupportDeepLink</span>(<span class="kw">true</span>)</a>
<a class="sourceLine" id="cb49-5" title="5">                  .<span class="fu">setAdCount</span>(<span class="dv">1</span>) <span class="co">//请求广告数量为1到3条</span></a>
<a class="sourceLine" id="cb49-6" title="6">                  .<span class="fu">setExpressViewAcceptedSize</span>(expressViewWidth,expressViewHeight) <span class="co">//期望个性化模板广告view的size,单位dp</span></a>
<a class="sourceLine" id="cb49-7" title="7">                  .<span class="fu">setImageAcceptedSize</span>(<span class="dv">640</span>,<span class="dv">320</span> )<span class="co">//这个参数设置即可，不影响个性化模板广告的size</span></a>
<a class="sourceLine" id="cb49-8" title="8">                  .<span class="fu">build</span>();</a>
<a class="sourceLine" id="cb49-9" title="9">       <span class="co">//加载广告</span></a>
<a class="sourceLine" id="cb49-10" title="10">         mTTAdNative.<span class="fu">loadInteractionExpressAd</span>(adSlot, <span class="kw">new</span> TTAdNative.<span class="fu">NativeExpressAdListener</span>() {</a>
<a class="sourceLine" id="cb49-11" title="11">                     <span class="at">@Override</span></a>
<a class="sourceLine" id="cb49-12" title="12">                     <span class="kw">public</span> <span class="dt">void</span> <span class="fu">onError</span>(<span class="dt">int</span> code, <span class="bu">String</span> message) {</a>
<a class="sourceLine" id="cb49-13" title="13">                         TToast.<span class="fu">show</span>(NativeExpressActivity.<span class="fu">this</span>, <span class="st">&quot;load error : &quot;</span> + code + <span class="st">&quot;, &quot;</span> + message);</a>
<a class="sourceLine" id="cb49-14" title="14">                         mExpressContainer.<span class="fu">removeAllViews</span>();</a>
<a class="sourceLine" id="cb49-15" title="15">                     }</a>
<a class="sourceLine" id="cb49-16" title="16">         </a>
<a class="sourceLine" id="cb49-17" title="17">                     <span class="at">@Override</span></a>
<a class="sourceLine" id="cb49-18" title="18">                     <span class="kw">public</span> <span class="dt">void</span> <span class="fu">onNativeExpressAdLoad</span>(<span class="bu">List</span>&lt;TTNativeExpressAd&gt; ads) {</a>
<a class="sourceLine" id="cb49-19" title="19">                         <span class="kw">if</span> (ads == <span class="kw">null</span> || ads.<span class="fu">size</span>() == <span class="dv">0</span>){</a>
<a class="sourceLine" id="cb49-20" title="20">                             <span class="kw">return</span>;</a>
<a class="sourceLine" id="cb49-21" title="21">                         }</a>
<a class="sourceLine" id="cb49-22" title="22">                         mTTAd = ads.<span class="fu">get</span>(<span class="dv">0</span>);</a>
<a class="sourceLine" id="cb49-23" title="23">                         <span class="fu">bindAdListener</span>(mTTAd);</a>
<a class="sourceLine" id="cb49-24" title="24">                         mTTAd.<span class="fu">render</span>();<span class="co">//调用render开始渲染广告</span></a>
<a class="sourceLine" id="cb49-25" title="25">                     }</a>
<a class="sourceLine" id="cb49-26" title="26">                 });</a>
<a class="sourceLine" id="cb49-27" title="27">    <span class="co">//绑定广告行为</span></a>
<a class="sourceLine" id="cb49-28" title="28">    <span class="kw">private</span> <span class="dt">void</span> <span class="fu">bindAdListener</span>(TTNativeExpressAd ad) {</a>
<a class="sourceLine" id="cb49-29" title="29">            ad.<span class="fu">setExpressInteractionListener</span>(<span class="kw">new</span> TTNativeExpressAd.<span class="fu">AdInteractionListener</span>() {</a>
<a class="sourceLine" id="cb49-30" title="30">                </a>
<a class="sourceLine" id="cb49-31" title="31">                <span class="at">@Override</span></a>
<a class="sourceLine" id="cb49-32" title="32">                <span class="kw">public</span> <span class="dt">void</span> <span class="fu">onAdDismiss</span>() {</a>
<a class="sourceLine" id="cb49-33" title="33">                    TToast.<span class="fu">show</span>(mContext, <span class="st">&quot;广告关闭&quot;</span>);</a>
<a class="sourceLine" id="cb49-34" title="34">                }</a>
<a class="sourceLine" id="cb49-35" title="35">                </a>
<a class="sourceLine" id="cb49-36" title="36">                <span class="at">@Override</span></a>
<a class="sourceLine" id="cb49-37" title="37">                <span class="kw">public</span> <span class="dt">void</span> <span class="fu">onAdClicked</span>(<span class="bu">View</span> view, <span class="dt">int</span> type) {</a>
<a class="sourceLine" id="cb49-38" title="38">                    TToast.<span class="fu">show</span>(mContext, <span class="st">&quot;广告被点击&quot;</span>);</a>
<a class="sourceLine" id="cb49-39" title="39">                }</a>
<a class="sourceLine" id="cb49-40" title="40">    </a>
<a class="sourceLine" id="cb49-41" title="41">                <span class="at">@Override</span></a>
<a class="sourceLine" id="cb49-42" title="42">                <span class="kw">public</span> <span class="dt">void</span> <span class="fu">onAdShow</span>(<span class="bu">View</span> view, <span class="dt">int</span> type) {</a>
<a class="sourceLine" id="cb49-43" title="43">                    TToast.<span class="fu">show</span>(mContext, <span class="st">&quot;广告展示&quot;</span>);</a>
<a class="sourceLine" id="cb49-44" title="44">                }</a>
<a class="sourceLine" id="cb49-45" title="45">    </a>
<a class="sourceLine" id="cb49-46" title="46">                <span class="at">@Override</span></a>
<a class="sourceLine" id="cb49-47" title="47">                <span class="kw">public</span> <span class="dt">void</span> <span class="fu">onRenderFail</span>(<span class="bu">View</span> view, <span class="bu">String</span> msg, <span class="dt">int</span> code) {</a>
<a class="sourceLine" id="cb49-48" title="48">                    Log.<span class="fu">e</span>(<span class="st">&quot;ExpressView&quot;</span>,<span class="st">&quot;render fail:&quot;</span>+(<span class="bu">System</span>.<span class="fu">currentTimeMillis</span>() - startTime));</a>
<a class="sourceLine" id="cb49-49" title="49">                    TToast.<span class="fu">show</span>(mContext, msg+<span class="st">&quot; code:&quot;</span>+code);</a>
<a class="sourceLine" id="cb49-50" title="50">                }</a>
<a class="sourceLine" id="cb49-51" title="51">    </a>
<a class="sourceLine" id="cb49-52" title="52">                <span class="at">@Override</span></a>
<a class="sourceLine" id="cb49-53" title="53">                <span class="kw">public</span> <span class="dt">void</span> <span class="fu">onRenderSuccess</span>(<span class="bu">View</span> view, <span class="dt">float</span> width, <span class="dt">float</span> height) {</a>
<a class="sourceLine" id="cb49-54" title="54">                    <span class="co">//返回view的宽高 单位 dp</span></a>
<a class="sourceLine" id="cb49-55" title="55">                    TToast.<span class="fu">show</span>(mContext, <span class="st">&quot;渲染成功&quot;</span>);</a>
<a class="sourceLine" id="cb49-56" title="56">                    <span class="co">//在渲染成功回调时展示广告，提升体验</span></a>
<a class="sourceLine" id="cb49-57" title="57">                    mExpressContainer.<span class="fu">removeAllViews</span>();</a>
<a class="sourceLine" id="cb49-58" title="58">                    mExpressContainer.<span class="fu">addView</span>(view);</a>
<a class="sourceLine" id="cb49-59" title="59">                }</a>
<a class="sourceLine" id="cb49-60" title="60">            });</a>
<a class="sourceLine" id="cb49-61" title="61">           </a>
<a class="sourceLine" id="cb49-62" title="62">            <span class="kw">if</span> (ad.<span class="fu">getInteractionType</span>() != TTAdConstant.<span class="fu">INTERACTION_TYPE_DOWNLOAD</span>){</a>
<a class="sourceLine" id="cb49-63" title="63">                <span class="kw">return</span>;</a>
<a class="sourceLine" id="cb49-64" title="64">            }</a>
<a class="sourceLine" id="cb49-65" title="65">            <span class="co">//可选，下载监听设置</span></a>
<a class="sourceLine" id="cb49-66" title="66">            ad.<span class="fu">setDownloadListener</span>(<span class="kw">new</span> <span class="fu">TTAppDownloadListener</span>() {</a>
<a class="sourceLine" id="cb49-67" title="67">                <span class="at">@Override</span></a>
<a class="sourceLine" id="cb49-68" title="68">                <span class="kw">public</span> <span class="dt">void</span> <span class="fu">onIdle</span>() {</a>
<a class="sourceLine" id="cb49-69" title="69">                    TToast.<span class="fu">show</span>(InteractionExpressActivity.<span class="fu">this</span>, <span class="st">&quot;点击开始下载&quot;</span>, Toast.<span class="fu">LENGTH_LONG</span>);</a>
<a class="sourceLine" id="cb49-70" title="70">                }</a>
<a class="sourceLine" id="cb49-71" title="71">    </a>
<a class="sourceLine" id="cb49-72" title="72">                <span class="at">@Override</span></a>
<a class="sourceLine" id="cb49-73" title="73">                <span class="kw">public</span> <span class="dt">void</span> <span class="fu">onDownloadActive</span>(<span class="dt">long</span> totalBytes, <span class="dt">long</span> currBytes, <span class="bu">String</span> fileName, <span class="bu">String</span> appName) {</a>
<a class="sourceLine" id="cb49-74" title="74">                    <span class="kw">if</span> (!mHasShowDownloadActive) {</a>
<a class="sourceLine" id="cb49-75" title="75">                        mHasShowDownloadActive = <span class="kw">true</span>;</a>
<a class="sourceLine" id="cb49-76" title="76">                        TToast.<span class="fu">show</span>(InteractionExpressActivity.<span class="fu">this</span>, <span class="st">&quot;下载中，点击暂停&quot;</span>, Toast.<span class="fu">LENGTH_LONG</span>);</a>
<a class="sourceLine" id="cb49-77" title="77">                    }</a>
<a class="sourceLine" id="cb49-78" title="78">                }</a>
<a class="sourceLine" id="cb49-79" title="79">    </a>
<a class="sourceLine" id="cb49-80" title="80">                <span class="at">@Override</span></a>
<a class="sourceLine" id="cb49-81" title="81">                <span class="kw">public</span> <span class="dt">void</span> <span class="fu">onDownloadPaused</span>(<span class="dt">long</span> totalBytes, <span class="dt">long</span> currBytes, <span class="bu">String</span> fileName, <span class="bu">String</span> appName) {</a>
<a class="sourceLine" id="cb49-82" title="82">                    TToast.<span class="fu">show</span>(InteractionExpressActivity.<span class="fu">this</span>, <span class="st">&quot;下载暂停，点击继续&quot;</span>, Toast.<span class="fu">LENGTH_LONG</span>);</a>
<a class="sourceLine" id="cb49-83" title="83">                }</a>
<a class="sourceLine" id="cb49-84" title="84">    </a>
<a class="sourceLine" id="cb49-85" title="85">                <span class="at">@Override</span></a>
<a class="sourceLine" id="cb49-86" title="86">                <span class="kw">public</span> <span class="dt">void</span> <span class="fu">onDownloadFailed</span>(<span class="dt">long</span> totalBytes, <span class="dt">long</span> currBytes, <span class="bu">String</span> fileName, <span class="bu">String</span> appName) {</a>
<a class="sourceLine" id="cb49-87" title="87">                    TToast.<span class="fu">show</span>(InteractionExpressActivity.<span class="fu">this</span>, <span class="st">&quot;下载失败，点击重新下载&quot;</span>, Toast.<span class="fu">LENGTH_LONG</span>);</a>
<a class="sourceLine" id="cb49-88" title="88">                }</a>
<a class="sourceLine" id="cb49-89" title="89">    </a>
<a class="sourceLine" id="cb49-90" title="90">                <span class="at">@Override</span></a>
<a class="sourceLine" id="cb49-91" title="91">                <span class="kw">public</span> <span class="dt">void</span> <span class="fu">onInstalled</span>(<span class="bu">String</span> fileName, <span class="bu">String</span> appName) {</a>
<a class="sourceLine" id="cb49-92" title="92">                    TToast.<span class="fu">show</span>(InteractionExpressActivity.<span class="fu">this</span>, <span class="st">&quot;安装完成，点击图片打开&quot;</span>, Toast.<span class="fu">LENGTH_LONG</span>);</a>
<a class="sourceLine" id="cb49-93" title="93">                }</a>
<a class="sourceLine" id="cb49-94" title="94">    </a>
<a class="sourceLine" id="cb49-95" title="95">                <span class="at">@Override</span></a>
<a class="sourceLine" id="cb49-96" title="96">                <span class="kw">public</span> <span class="dt">void</span> <span class="fu">onDownloadFinished</span>(<span class="dt">long</span> totalBytes, <span class="bu">String</span> fileName, <span class="bu">String</span> appName) {</a>
<a class="sourceLine" id="cb49-97" title="97">                    TToast.<span class="fu">show</span>(InteractionExpressActivity.<span class="fu">this</span>, <span class="st">&quot;点击安装&quot;</span>, Toast.<span class="fu">LENGTH_LONG</span>);</a>
<a class="sourceLine" id="cb49-98" title="98">                }</a>
<a class="sourceLine" id="cb49-99" title="99">            });</a>
<a class="sourceLine" id="cb49-100" title="100">        }</a>
<a class="sourceLine" id="cb49-101" title="101">        </a>
<a class="sourceLine" id="cb49-102" title="102">        <span class="co">//在合适的时机，释放广告的资源</span></a>
<a class="sourceLine" id="cb49-103" title="103">        <span class="at">@Override</span></a>
<a class="sourceLine" id="cb49-104" title="104">        <span class="kw">protected</span> <span class="dt">void</span> <span class="fu">onDestroy</span>() {</a>
<a class="sourceLine" id="cb49-105" title="105">            <span class="kw">super</span>.<span class="fu">onDestroy</span>();</a>
<a class="sourceLine" id="cb49-106" title="106">            <span class="kw">if</span> (mTTAd != <span class="kw">null</span>) {</a>
<a class="sourceLine" id="cb49-107" title="107">                <span class="co">//调用destroy()方法释放</span></a>
<a class="sourceLine" id="cb49-108" title="108">                mTTAd.<span class="fu">destroy</span>();</a>
<a class="sourceLine" id="cb49-109" title="109">            }</a>
<a class="sourceLine" id="cb49-110" title="110">        }</a></code></pre></div>
<h4 id="展示个性化模板插屏广告">2.14.2 展示个性化模板插屏广告</h4>
<div class="sourceCode" id="cb50"><pre class="sourceCode java"><code class="sourceCode java"><a class="sourceLine" id="cb50-1" title="1"> <span class="kw">public</span> <span class="dt">void</span> <span class="fu">onRenderSuccess</span>(<span class="bu">View</span> view, <span class="dt">float</span> width, <span class="dt">float</span> height) {</a>
<a class="sourceLine" id="cb50-2" title="2">                    <span class="co">//返回view的宽高 单位 dp</span></a>
<a class="sourceLine" id="cb50-3" title="3">                    TToast.<span class="fu">show</span>(mContext, <span class="st">&quot;渲染成功&quot;</span>);</a>
<a class="sourceLine" id="cb50-4" title="4">                    <span class="co">//在渲染成功回调时展示广告，提升体验</span></a>
<a class="sourceLine" id="cb50-5" title="5">                       mTTAd.<span class="fu">showInteractionExpressAd</span>(InteractionExpressActivity.<span class="fu">this</span>);</a>
<a class="sourceLine" id="cb50-6" title="6">                }</a></code></pre></div>
<p>加载到广告后，调用TTNativeExpressAd.render()方法渲染广告，在onRenderSuccess(View view, float width, float height)方法 回调中，调用展示插屏广告。详细代码请参考demo中的InteractionExpressActivity示例。</p>
<h3 id="接入个性化模板draw视频广告接口同-ttnativeexpressad">2.15 接入个性化模板Draw视频广告（接口同 TTNativeExpressAd）</h3>
<p>本SDK为接入方提供个性化模板Draw广告，开发者不用自行对广告样式进行编辑和渲染，可直接调用相关接口获取广告view,广告样式模板以及微调后期支持开发者编辑。</p>
<h4 id="加载个性化模板draw视频广告绑定接口回调">2.15.1 加载个性化模板Draw视频广告，绑定接口回调</h4>
<p>接入方可调用<code>loadExpressDrawFeedAd(AdSlot adSlot, @NonNull NativeExpressAdListener listener)</code>异步加载广告，adslot为请求广告的信息，NativeExpressAdListener为广告加载成功或失败等回调。</p>
<p><strong>注意</strong>:期望个性化模板尺寸的参数设置中，个性化模板Draw视频广告高度不能设置为0,尺寸大小请保持和平台设置一致;<strong>个性化模板Draw广告不支持dislike逻辑。</strong></p>
<div class="sourceCode" id="cb51"><pre class="sourceCode java"><code class="sourceCode java"><a class="sourceLine" id="cb51-1" title="1"> <span class="co">//设置广告参数</span></a>
<a class="sourceLine" id="cb51-2" title="2">   AdSlot adSlot = <span class="kw">new</span> AdSlot.<span class="fu">Builder</span>()</a>
<a class="sourceLine" id="cb51-3" title="3">                  .<span class="fu">setCodeId</span>(codeId) <span class="co">//广告位id</span></a>
<a class="sourceLine" id="cb51-4" title="4">                  .<span class="fu">setSupportDeepLink</span>(<span class="kw">true</span>)</a>
<a class="sourceLine" id="cb51-5" title="5">                  .<span class="fu">setAdCount</span>(<span class="dv">1</span>) <span class="co">//请求广告数量为1到3条</span></a>
<a class="sourceLine" id="cb51-6" title="6">                  .<span class="fu">setExpressViewAcceptedSize</span>(expressViewWidth,expressViewHeight) <span class="co">//期望个性化模板广告view的size,单位dp</span></a>
<a class="sourceLine" id="cb51-7" title="7">                  .<span class="fu">setImageAcceptedSize</span>(<span class="dv">640</span>,<span class="dv">320</span> )<span class="co">//这个参数设置即可，不影响个性化模板广告的size</span></a>
<a class="sourceLine" id="cb51-8" title="8">                  .<span class="fu">build</span>();</a>
<a class="sourceLine" id="cb51-9" title="9">       <span class="co">//加载广告</span></a>
<a class="sourceLine" id="cb51-10" title="10">         mTTAdNative.<span class="fu">loadExpressDrawFeedAd</span>(adSlot, <span class="kw">new</span> TTAdNative.<span class="fu">NativeExpressAdListener</span>() {</a>
<a class="sourceLine" id="cb51-11" title="11">                     <span class="at">@Override</span></a>
<a class="sourceLine" id="cb51-12" title="12">                     <span class="kw">public</span> <span class="dt">void</span> <span class="fu">onError</span>(<span class="dt">int</span> code, <span class="bu">String</span> message) {</a>
<a class="sourceLine" id="cb51-13" title="13">                         TToast.<span class="fu">show</span>(DrawNativeExpressVideoActivity.<span class="fu">this</span>, <span class="st">&quot;load error : &quot;</span> + code + <span class="st">&quot;, &quot;</span> + message);</a>
<a class="sourceLine" id="cb51-14" title="14">                     }</a>
<a class="sourceLine" id="cb51-15" title="15">         </a>
<a class="sourceLine" id="cb51-16" title="16">                     <span class="at">@Override</span></a>
<a class="sourceLine" id="cb51-17" title="17">                     <span class="kw">public</span> <span class="dt">void</span> <span class="fu">onNativeExpressAdLoad</span>(<span class="bu">List</span>&lt;TTNativeExpressAd&gt; ads) {</a>
<a class="sourceLine" id="cb51-18" title="18">                         <span class="kw">if</span> (ads == <span class="kw">null</span> || ads.<span class="fu">size</span>() == <span class="dv">0</span>){</a>
<a class="sourceLine" id="cb51-19" title="19">                             <span class="kw">return</span>;</a>
<a class="sourceLine" id="cb51-20" title="20">                         }</a>
<a class="sourceLine" id="cb51-21" title="21">                         <span class="kw">for</span> (<span class="dt">final</span> TTNativeExpressAd ad : ads) {</a>
<a class="sourceLine" id="cb51-22" title="22">                         <span class="co">//设置监听回调</span></a>
<a class="sourceLine" id="cb51-23" title="23">                         ad.<span class="fu">setVideoAdListener</span>(<span class="kw">new</span> TTNativeExpressAd.<span class="fu">ExpressVideoAdListener</span>() {<span class="co">//略});</span></a>
<a class="sourceLine" id="cb51-24" title="24">                         <span class="co">//是否允许点击暂停视频播放</span></a>
<a class="sourceLine" id="cb51-25" title="25">                         ad.<span class="fu">setCanInterruptVideoPlay</span>(<span class="kw">true</span>);</a>
<a class="sourceLine" id="cb51-26" title="26">                         ad.<span class="fu">setExpressInteractionListener</span>(<span class="kw">new</span> TTNativeExpressAd.<span class="fu">ExpressAdInteractionListener</span>() {</a>
<a class="sourceLine" id="cb51-27" title="27">                             <span class="at">@Override</span></a>
<a class="sourceLine" id="cb51-28" title="28">                             <span class="kw">public</span> <span class="dt">void</span> <span class="fu">onAdClicked</span>(<span class="bu">View</span> view, <span class="dt">int</span> type) {</a>
<a class="sourceLine" id="cb51-29" title="29"></a>
<a class="sourceLine" id="cb51-30" title="30">                             }</a>
<a class="sourceLine" id="cb51-31" title="31"></a>
<a class="sourceLine" id="cb51-32" title="32">                             <span class="at">@Override</span></a>
<a class="sourceLine" id="cb51-33" title="33">                             <span class="kw">public</span> <span class="dt">void</span> <span class="fu">onAdShow</span>(<span class="bu">View</span> view, <span class="dt">int</span> type) {</a>
<a class="sourceLine" id="cb51-34" title="34"></a>
<a class="sourceLine" id="cb51-35" title="35">                             }</a>
<a class="sourceLine" id="cb51-36" title="36"></a>
<a class="sourceLine" id="cb51-37" title="37">                             <span class="at">@Override</span></a>
<a class="sourceLine" id="cb51-38" title="38">                            <span class="kw">public</span> <span class="dt">void</span> <span class="fu">onRenderFail</span>(<span class="bu">View</span> view, <span class="bu">String</span> msg, <span class="dt">int</span> code) {</a>
<a class="sourceLine" id="cb51-39" title="39"></a>
<a class="sourceLine" id="cb51-40" title="40">                             }</a>
<a class="sourceLine" id="cb51-41" title="41"></a>
<a class="sourceLine" id="cb51-42" title="42">                             <span class="at">@Override</span></a>
<a class="sourceLine" id="cb51-43" title="43">                             <span class="kw">public</span> <span class="dt">void</span> <span class="fu">onRenderSuccess</span>(<span class="bu">View</span> view, <span class="dt">float</span> width, <span class="dt">float</span> height) {</a>
<a class="sourceLine" id="cb51-44" title="44">                             TToast.<span class="fu">show</span>(DrawNativeExpressVideoActivity.<span class="fu">this</span>, <span class="st">&quot;渲染成功&quot;</span>);</a>
<a class="sourceLine" id="cb51-45" title="45">                             <span class="dt">int</span> random = (<span class="dt">int</span>) (<span class="bu">Math</span>.<span class="fu">random</span>() * <span class="dv">100</span>);</a>
<a class="sourceLine" id="cb51-46" title="46">                             <span class="dt">int</span> index = random % videos.<span class="fu">length</span>;</a>
<a class="sourceLine" id="cb51-47" title="47">                             <span class="kw">if</span> (index == <span class="dv">0</span>){</a>
<a class="sourceLine" id="cb51-48" title="48">                                    index++;</a>
<a class="sourceLine" id="cb51-49" title="49">                             }</a>
<a class="sourceLine" id="cb51-50" title="50">                             datas.<span class="fu">add</span>(index, <span class="kw">new</span> <span class="fu">Item</span>(TYPE_AD_ITEM, ad, -<span class="dv">1</span>, -<span class="dv">1</span>));</a>
<a class="sourceLine" id="cb51-51" title="51">                             mAdapter.<span class="fu">notifyDataSetChanged</span>();</a>
<a class="sourceLine" id="cb51-52" title="52">                             }</a>
<a class="sourceLine" id="cb51-53" title="53">                          });</a>
<a class="sourceLine" id="cb51-54" title="54">                         ad.<span class="fu">render</span>();<span class="co">//调用render开始渲染广告</span></a>
<a class="sourceLine" id="cb51-55" title="55">                     }</a>
<a class="sourceLine" id="cb51-56" title="56">                 });</a>
<a class="sourceLine" id="cb51-57" title="57">            }</a>
<a class="sourceLine" id="cb51-58" title="58">        </a>
<a class="sourceLine" id="cb51-59" title="59">        <span class="co">//在合适的时机，释放广告的资源</span></a>
<a class="sourceLine" id="cb51-60" title="60">        <span class="at">@Override</span></a>
<a class="sourceLine" id="cb51-61" title="61">        <span class="kw">protected</span> <span class="dt">void</span> <span class="fu">onDestroy</span>() {</a>
<a class="sourceLine" id="cb51-62" title="62">            <span class="kw">super</span>.<span class="fu">onDestroy</span>();</a>
<a class="sourceLine" id="cb51-63" title="63">            <span class="kw">if</span> (mTTAd != <span class="kw">null</span>) {</a>
<a class="sourceLine" id="cb51-64" title="64">                <span class="co">//调用destroy()方法释放</span></a>
<a class="sourceLine" id="cb51-65" title="65">                mTTAd.<span class="fu">destroy</span>();</a>
<a class="sourceLine" id="cb51-66" title="66">            }</a>
<a class="sourceLine" id="cb51-67" title="67">        }</a></code></pre></div>
<h4 id="展示个性化模板draw视频广告">2.15.2 展示个性化模板Draw视频广告</h4>
<div class="sourceCode" id="cb52"><pre class="sourceCode java"><code class="sourceCode java"><a class="sourceLine" id="cb52-1" title="1"> <span class="kw">public</span> <span class="dt">void</span> <span class="fu">onRenderSuccess</span>(<span class="bu">View</span> view, <span class="dt">float</span> width, <span class="dt">float</span> height) {</a>
<a class="sourceLine" id="cb52-2" title="2">                    <span class="co">//返回view的宽高 单位 dp</span></a>
<a class="sourceLine" id="cb52-3" title="3">                    TToast.<span class="fu">show</span>(mContext, <span class="st">&quot;渲染成功&quot;</span>);</a>
<a class="sourceLine" id="cb52-4" title="4">                    <span class="co">//在渲染成功回调时将广告加入页面中，提升体验</span></a>
<a class="sourceLine" id="cb52-5" title="5">                    <span class="co">//todo 接入中完善更新逻辑</span></a>
<a class="sourceLine" id="cb52-6" title="6">                }</a></code></pre></div>
<p>加载到广告后，调用TTNativeExpressAd.render()方法渲染广告，在onRenderSuccess(View view, float width, float height)方法 回调中，处理添加广告的逻辑。详细代码请参考demo中的DrawNativeExpressVideoActivity示例。</p>
<h3 id="下载监听器注册">2.16 下载监听器注册：</h3>
<p>SDK针对应用下载广告提供了下载状态监听器，接入方可注册该监听器以监听下载状态的变化，监听器支持未下载、下载中、下载暂停、下载失败、下载完成、安装完成的回调。</p>
<h4 id="下载监听回调说明">2.16.1 下载监听回调说明</h4>
<div class="sourceCode" id="cb53"><pre class="sourceCode java"><code class="sourceCode java"><a class="sourceLine" id="cb53-1" title="1"><span class="kw">public</span> <span class="kw">interface</span> TTAppDownloadListener {</a>
<a class="sourceLine" id="cb53-2" title="2"></a>
<a class="sourceLine" id="cb53-3" title="3">    <span class="dt">void</span> <span class="fu">onIdle</span>(); <span class="co">// 未开始下载</span></a>
<a class="sourceLine" id="cb53-4" title="4"></a>
<a class="sourceLine" id="cb53-5" title="5">    <span class="co">/**</span></a>
<a class="sourceLine" id="cb53-6" title="6">     <span class="co">*</span> 下载中回调</a>
<a class="sourceLine" id="cb53-7" title="7">     <span class="co">* </span><span class="an">@param totalBytes </span>安装包总字节数 <span class="co">-1</span> ：未知</a>
<a class="sourceLine" id="cb53-8" title="8">     <span class="co">*</span> <span class="an">@param currBytes </span>当前已下载的字节数</a>
<a class="sourceLine" id="cb53-9" title="9">     <span class="co">*</span> <span class="an">@param fileName </span>下载文件名称</a>
<a class="sourceLine" id="cb53-10" title="10">     <span class="co">*</span> <span class="an">@param appName </span>当前下载的APP名</a>
<a class="sourceLine" id="cb53-11" title="11">     <span class="co">*/</span></a>
<a class="sourceLine" id="cb53-12" title="12">    <span class="dt">void</span> <span class="fu">onDownloadActive</span>(<span class="dt">long</span> totalBytes, <span class="dt">long</span> currBytes, <span class="bu">String</span> fileName, <span class="bu">String</span> appName); <span class="co">// 下载中</span></a>
<a class="sourceLine" id="cb53-13" title="13"></a>
<a class="sourceLine" id="cb53-14" title="14">    <span class="co">/**</span></a>
<a class="sourceLine" id="cb53-15" title="15">     <span class="co">*</span> 下载暂停回调</a>
<a class="sourceLine" id="cb53-16" title="16">     <span class="co">* </span><span class="an">@param totalBytes </span>安装包总字节数 <span class="co">-1</span> ：未知</a>
<a class="sourceLine" id="cb53-17" title="17">     <span class="co">*</span> <span class="an">@param currBytes </span>当前已下载的字节数</a>
<a class="sourceLine" id="cb53-18" title="18">     <span class="co">*</span> <span class="an">@param fileName </span>下载文件名称</a>
<a class="sourceLine" id="cb53-19" title="19">     <span class="co">*</span> <span class="an">@param appName </span>当前下载的APP名</a>
<a class="sourceLine" id="cb53-20" title="20">     <span class="co">*/</span></a>
<a class="sourceLine" id="cb53-21" title="21">    <span class="dt">void</span> <span class="fu">onDownloadPaused</span>(<span class="dt">long</span> totalBytes, <span class="dt">long</span> currBytes, <span class="bu">String</span> fileName, <span class="bu">String</span> appName);</a>
<a class="sourceLine" id="cb53-22" title="22"></a>
<a class="sourceLine" id="cb53-23" title="23">    <span class="co">/**</span></a>
<a class="sourceLine" id="cb53-24" title="24">     <span class="co">*</span> 下载失败回调</a>
<a class="sourceLine" id="cb53-25" title="25">     <span class="co">* </span><span class="an">@param totalBytes </span>安装包总字节数 <span class="co">-1</span> ：未知</a>
<a class="sourceLine" id="cb53-26" title="26">     <span class="co">*</span> <span class="an">@param currBytes </span>当前已下载的字节数</a>
<a class="sourceLine" id="cb53-27" title="27">     <span class="co">*</span> <span class="an">@param fileName </span>下载文件名称</a>
<a class="sourceLine" id="cb53-28" title="28">     <span class="co">*</span> <span class="an">@param appName </span>当前下载的APP名</a>
<a class="sourceLine" id="cb53-29" title="29">     <span class="co">*/</span></a>
<a class="sourceLine" id="cb53-30" title="30">    <span class="dt">void</span> <span class="fu">onDownloadFailed</span>(<span class="dt">long</span> totalBytes, <span class="dt">long</span> currBytes, <span class="bu">String</span> fileName, <span class="bu">String</span> appName);</a>
<a class="sourceLine" id="cb53-31" title="31"></a>
<a class="sourceLine" id="cb53-32" title="32">    <span class="co">/**</span></a>
<a class="sourceLine" id="cb53-33" title="33">     <span class="co">*</span> 下载完成回调</a>
<a class="sourceLine" id="cb53-34" title="34">     <span class="co">* </span><span class="an">@param totalBytes </span>安装包总字节数 <span class="co">-1</span> ：未知</a>
<a class="sourceLine" id="cb53-35" title="35">     <span class="co">*</span> <span class="an">@param fileName </span>下载文件名称</a>
<a class="sourceLine" id="cb53-36" title="36">     <span class="co">*</span> <span class="an">@param appName </span>当前下载的APP名</a>
<a class="sourceLine" id="cb53-37" title="37">     <span class="co">*/</span></a>
<a class="sourceLine" id="cb53-38" title="38">    <span class="dt">void</span> <span class="fu">onDownloadFinished</span>(<span class="dt">long</span> totalBytes, <span class="bu">String</span> fileName, <span class="bu">String</span> appName);</a>
<a class="sourceLine" id="cb53-39" title="39"></a>
<a class="sourceLine" id="cb53-40" title="40">    <span class="co">/**</span></a>
<a class="sourceLine" id="cb53-41" title="41">     <span class="co">*</span> 安装完成回调</a>
<a class="sourceLine" id="cb53-42" title="42">     <span class="co">* </span><span class="an">@param fileName </span>下载文件名称</a>
<a class="sourceLine" id="cb53-43" title="43">     <span class="co">*</span> <span class="an">@param appName </span>当前下载的APP名</a>
<a class="sourceLine" id="cb53-44" title="44">     <span class="co">*/</span></a>
<a class="sourceLine" id="cb53-45" title="45">    <span class="dt">void</span> <span class="fu">onInstalled</span>(<span class="bu">String</span> fileName, <span class="bu">String</span> appName);</a>
<a class="sourceLine" id="cb53-46" title="46"></a>
<a class="sourceLine" id="cb53-47" title="47">}</a></code></pre></div>
<h4 id="注册下载监听器">2.16.2 注册下载监听器</h4>
<p>当返回的广告为应用下载类型，即ad.getInteractionType() == TTAdConstant.INTERACTION_TYPE_DOWNLOAD时，接入方可调用如下示例代码注册下载监听器：</p>
<div class="sourceCode" id="cb54"><pre class="sourceCode java"><code class="sourceCode java"><a class="sourceLine" id="cb54-1" title="1">TTAppDownloadListener downloadListener = <span class="kw">new</span> <span class="fu">TTAppDownloadListener</span>() {</a>
<a class="sourceLine" id="cb54-2" title="2">        <span class="at">@Override</span></a>
<a class="sourceLine" id="cb54-3" title="3">        <span class="kw">public</span> <span class="dt">void</span> <span class="fu">onIdle</span>() {</a>
<a class="sourceLine" id="cb54-4" title="4">            <span class="kw">if</span> (!<span class="fu">isValid</span>()) {</a>
<a class="sourceLine" id="cb54-5" title="5">                <span class="kw">return</span>;</a>
<a class="sourceLine" id="cb54-6" title="6">            }</a>
<a class="sourceLine" id="cb54-7" title="7">            adCreativeButton.<span class="fu">setText</span>(<span class="st">&quot;开始下载&quot;</span>);</a>
<a class="sourceLine" id="cb54-8" title="8">            adViewHolder.<span class="fu">mStopButton</span>.<span class="fu">setText</span>(<span class="st">&quot;开始下载&quot;</span>);</a>
<a class="sourceLine" id="cb54-9" title="9">        }</a>
<a class="sourceLine" id="cb54-10" title="10">    </a>
<a class="sourceLine" id="cb54-11" title="11">        <span class="at">@Override</span></a>
<a class="sourceLine" id="cb54-12" title="12">        <span class="kw">public</span> <span class="dt">void</span> <span class="fu">onDownloadActive</span>(<span class="dt">long</span> totalBytes, <span class="dt">long</span> currBytes, <span class="bu">String</span> fileName, <span class="bu">String</span> appName) {</a>
<a class="sourceLine" id="cb54-13" title="13">            <span class="kw">if</span> (!<span class="fu">isValid</span>()) {</a>
<a class="sourceLine" id="cb54-14" title="14">                <span class="kw">return</span>;</a>
<a class="sourceLine" id="cb54-15" title="15">            }</a>
<a class="sourceLine" id="cb54-16" title="16">            <span class="kw">if</span> (totalBytes &lt; <span class="dv">0L</span>) {</a>
<a class="sourceLine" id="cb54-17" title="17">                adCreativeButton.<span class="fu">setText</span>(<span class="st">&quot;下载中 percent: 0&quot;</span>);</a>
<a class="sourceLine" id="cb54-18" title="18">            } <span class="kw">else</span> {</a>
<a class="sourceLine" id="cb54-19" title="19">                adCreativeButton.<span class="fu">setText</span>(<span class="st">&quot;下载中 percent: &quot;</span> + (currBytes * <span class="dv">100</span> / totalBytes));</a>
<a class="sourceLine" id="cb54-20" title="20">            }</a>
<a class="sourceLine" id="cb54-21" title="21">            adViewHolder.<span class="fu">mStopButton</span>.<span class="fu">setText</span>(<span class="st">&quot;下载中&quot;</span>);</a>
<a class="sourceLine" id="cb54-22" title="22">        }</a>
<a class="sourceLine" id="cb54-23" title="23">    </a>
<a class="sourceLine" id="cb54-24" title="24">        <span class="at">@Override</span></a>
<a class="sourceLine" id="cb54-25" title="25">        <span class="kw">public</span> <span class="dt">void</span> <span class="fu">onDownloadPaused</span>(<span class="dt">long</span> totalBytes, <span class="dt">long</span> currBytes, <span class="bu">String</span> fileName, <span class="bu">String</span> appName) {</a>
<a class="sourceLine" id="cb54-26" title="26">            <span class="kw">if</span> (!<span class="fu">isValid</span>()) {</a>
<a class="sourceLine" id="cb54-27" title="27">                <span class="kw">return</span>;</a>
<a class="sourceLine" id="cb54-28" title="28">            }</a>
<a class="sourceLine" id="cb54-29" title="29">            adCreativeButton.<span class="fu">setText</span>(<span class="st">&quot;下载暂停 percent: &quot;</span> + (currBytes * <span class="dv">100</span> / totalBytes));</a>
<a class="sourceLine" id="cb54-30" title="30">            adViewHolder.<span class="fu">mStopButton</span>.<span class="fu">setText</span>(<span class="st">&quot;下载暂停&quot;</span>);</a>
<a class="sourceLine" id="cb54-31" title="31">        }</a>
<a class="sourceLine" id="cb54-32" title="32">    </a>
<a class="sourceLine" id="cb54-33" title="33">        <span class="at">@Override</span></a>
<a class="sourceLine" id="cb54-34" title="34">        <span class="kw">public</span> <span class="dt">void</span> <span class="fu">onDownloadFailed</span>(<span class="dt">long</span> totalBytes, <span class="dt">long</span> currBytes, <span class="bu">String</span> fileName, <span class="bu">String</span> appName) {</a>
<a class="sourceLine" id="cb54-35" title="35">            <span class="kw">if</span> (!<span class="fu">isValid</span>()) {</a>
<a class="sourceLine" id="cb54-36" title="36">                <span class="kw">return</span>;</a>
<a class="sourceLine" id="cb54-37" title="37">            }</a>
<a class="sourceLine" id="cb54-38" title="38">            adCreativeButton.<span class="fu">setText</span>(<span class="st">&quot;重新下载&quot;</span>);</a>
<a class="sourceLine" id="cb54-39" title="39">            adViewHolder.<span class="fu">mStopButton</span>.<span class="fu">setText</span>(<span class="st">&quot;重新下载&quot;</span>);</a>
<a class="sourceLine" id="cb54-40" title="40">        }</a>
<a class="sourceLine" id="cb54-41" title="41">    </a>
<a class="sourceLine" id="cb54-42" title="42">        <span class="at">@Override</span></a>
<a class="sourceLine" id="cb54-43" title="43">        <span class="kw">public</span> <span class="dt">void</span> <span class="fu">onInstalled</span>(<span class="bu">String</span> fileName, <span class="bu">String</span> appName) {</a>
<a class="sourceLine" id="cb54-44" title="44">            <span class="kw">if</span> (!<span class="fu">isValid</span>()) {</a>
<a class="sourceLine" id="cb54-45" title="45">                <span class="kw">return</span>;</a>
<a class="sourceLine" id="cb54-46" title="46">            }</a>
<a class="sourceLine" id="cb54-47" title="47">            adCreativeButton.<span class="fu">setText</span>(<span class="st">&quot;点击打开&quot;</span>);</a>
<a class="sourceLine" id="cb54-48" title="48">            adViewHolder.<span class="fu">mStopButton</span>.<span class="fu">setText</span>(<span class="st">&quot;点击打开&quot;</span>);</a>
<a class="sourceLine" id="cb54-49" title="49">        }</a>
<a class="sourceLine" id="cb54-50" title="50">    </a>
<a class="sourceLine" id="cb54-51" title="51">        <span class="at">@Override</span></a>
<a class="sourceLine" id="cb54-52" title="52">        <span class="kw">public</span> <span class="dt">void</span> <span class="fu">onDownloadFinished</span>(<span class="dt">long</span> totalBytes, <span class="bu">String</span> fileName, <span class="bu">String</span> appName) {</a>
<a class="sourceLine" id="cb54-53" title="53">            <span class="kw">if</span> (!<span class="fu">isValid</span>()) {</a>
<a class="sourceLine" id="cb54-54" title="54">                <span class="kw">return</span>;</a>
<a class="sourceLine" id="cb54-55" title="55">            }</a>
<a class="sourceLine" id="cb54-56" title="56">            adCreativeButton.<span class="fu">setText</span>(<span class="st">&quot;点击安装&quot;</span>);</a>
<a class="sourceLine" id="cb54-57" title="57">            adViewHolder.<span class="fu">mStopButton</span>.<span class="fu">setText</span>(<span class="st">&quot;点击安装&quot;</span>);</a>
<a class="sourceLine" id="cb54-58" title="58">        }</a>
<a class="sourceLine" id="cb54-59" title="59">    </a>
<a class="sourceLine" id="cb54-60" title="60">        <span class="kw">private</span> <span class="dt">boolean</span> <span class="fu">isValid</span>() {</a>
<a class="sourceLine" id="cb54-61" title="61">            <span class="kw">return</span> mTTAppDownloadListenerMap.<span class="fu">get</span>(adViewHolder) == <span class="kw">this</span>;</a>
<a class="sourceLine" id="cb54-62" title="62">        }</a>
<a class="sourceLine" id="cb54-63" title="63">};</a>
<a class="sourceLine" id="cb54-64" title="64">ad.<span class="fu">setDownloadListener</span>(downloadListener); <span class="co">// 注册下载监听器</span></a></code></pre></div>
<p>下载监听器的注册详细示例详见Demo中的FeedActivity及BannerActivity的bindDownloadListener()方法。</p>
<h3 id="feed广告下载状态控制器">2.17 Feed广告下载状态控制器</h3>
<p>在信息流广告中，SDK为接入方提供广告APP下载状态控制器接口，接入方可以通过该接口控制信息流广告App的下载状态，例如：暂停下载、继续下载、取消下载；<br />
<strong>注意：该控制器只能控制信息流广告中的下载状态，如需要控制Banner、Intercation广告中的下载状态，请使用TTGlobalAppDownloadController</strong></p>
<h4 id="feed广告下载状态控制器接口说明">2.17.1 Feed广告下载状态控制器接口说明</h4>
<div class="sourceCode" id="cb55"><pre class="sourceCode java"><code class="sourceCode java"><a class="sourceLine" id="cb55-1" title="1"> <span class="kw">public</span> <span class="kw">interface</span> DownloadStatusController {</a>
<a class="sourceLine" id="cb55-2" title="2"></a>
<a class="sourceLine" id="cb55-3" title="3">    <span class="co">/**</span></a>
<a class="sourceLine" id="cb55-4" title="4">     <span class="co">*</span> 在未点击创意按钮开始下载时调用，则会无效</a>
<a class="sourceLine" id="cb55-5" title="5">     <span class="co">*</span> 在正在下载中调用，则会暂停下载  【正在下载】--<span class="co">&gt;</span>【暂停下载】</a>
<a class="sourceLine" id="cb55-6" title="6">     <span class="co">*</span> 在暂停时调用，则会继续下载    【暂停下载】--<span class="co">&gt;</span>【继续下载】</a>
<a class="sourceLine" id="cb55-7" title="7">     <span class="co">*/</span></a>
<a class="sourceLine" id="cb55-8" title="8">    <span class="dt">void</span> <span class="fu">changeDownloadStatus</span>();</a>
<a class="sourceLine" id="cb55-9" title="9"></a>
<a class="sourceLine" id="cb55-10" title="10">    <span class="co">/**</span></a>
<a class="sourceLine" id="cb55-11" title="11">     <span class="co">*</span> 取消当前下载任务</a>
<a class="sourceLine" id="cb55-12" title="12">     <span class="co">*/</span></a>
<a class="sourceLine" id="cb55-13" title="13">    <span class="dt">void</span> <span class="fu">cancelDownload</span>();</a>
<a class="sourceLine" id="cb55-14" title="14">} </a></code></pre></div>
<h4 id="接入feed广告app下载状态控制器">2.17.2 接入Feed广告App下载状态控制器</h4>
<p>当返回的广告为应用下载类型，即ad.getInteractionType() == TTAdConstant.INTERACTION_TYPE_DOWNLOAD时，接入方可调用如下示例代码接入Feed广告下载控制器：</p>
<div class="sourceCode" id="cb56"><pre class="sourceCode java"><code class="sourceCode java"><a class="sourceLine" id="cb56-1" title="1"><span class="kw">private</span> <span class="dt">void</span> <span class="fu">bindDownLoadStatusController</span>(AdViewHolder adViewHolder, <span class="dt">final</span> TTFeedAd ad) {</a>
<a class="sourceLine" id="cb56-2" title="2">    <span class="dt">final</span> DownloadStatusController controller = ad.<span class="fu">getDownloadStatusController</span>();</a>
<a class="sourceLine" id="cb56-3" title="3">    adViewHolder.<span class="fu">mStopButton</span>.<span class="fu">setOnClickListener</span>(<span class="kw">new</span> <span class="bu">View</span>.<span class="fu">OnClickListener</span>() {</a>
<a class="sourceLine" id="cb56-4" title="4">        <span class="at">@Override</span></a>
<a class="sourceLine" id="cb56-5" title="5">        <span class="kw">public</span> <span class="dt">void</span> <span class="fu">onClick</span>(<span class="bu">View</span> v) {</a>
<a class="sourceLine" id="cb56-6" title="6">            <span class="kw">if</span> (controller != <span class="kw">null</span>) {</a>
<a class="sourceLine" id="cb56-7" title="7">                controller.<span class="fu">changeDownloadStatus</span>();</a>
<a class="sourceLine" id="cb56-8" title="8">                Toast.<span class="fu">makeText</span>(mContext, <span class="st">&quot;改变下载状态&quot;</span>, Toast.<span class="fu">LENGTH_SHORT</span>).<span class="fu">show</span>();</a>
<a class="sourceLine" id="cb56-9" title="9">                Log.<span class="fu">d</span>(TAG, <span class="st">&quot;改变下载状态&quot;</span>);</a>
<a class="sourceLine" id="cb56-10" title="10">            }</a>
<a class="sourceLine" id="cb56-11" title="11">        }</a>
<a class="sourceLine" id="cb56-12" title="12">        });</a>
<a class="sourceLine" id="cb56-13" title="13">    adViewHolder.<span class="fu">mRemoveButton</span>.<span class="fu">setOnClickListener</span>(<span class="kw">new</span> <span class="bu">View</span>.<span class="fu">OnClickListener</span>() {</a>
<a class="sourceLine" id="cb56-14" title="14">        <span class="at">@Override</span></a>
<a class="sourceLine" id="cb56-15" title="15">        <span class="kw">public</span> <span class="dt">void</span> <span class="fu">onClick</span>(<span class="bu">View</span> v) {</a>
<a class="sourceLine" id="cb56-16" title="16">            <span class="kw">if</span> (controller != <span class="kw">null</span>) {</a>
<a class="sourceLine" id="cb56-17" title="17">                controller.<span class="fu">cancelDownload</span>();</a>
<a class="sourceLine" id="cb56-18" title="18">                Toast.<span class="fu">makeText</span>(mContext, <span class="st">&quot;取消下载&quot;</span>, Toast.<span class="fu">LENGTH_SHORT</span>).<span class="fu">show</span>();</a>
<a class="sourceLine" id="cb56-19" title="19">                Log.<span class="fu">d</span>(TAG, <span class="st">&quot;取消下载&quot;</span>);</a>
<a class="sourceLine" id="cb56-20" title="20">            }</a>
<a class="sourceLine" id="cb56-21" title="21">        }</a>
<a class="sourceLine" id="cb56-22" title="22">    });</a>
<a class="sourceLine" id="cb56-23" title="23">}</a></code></pre></div>
<p>接入DownloadStatusController的具体示例详见Demo中的FeedActivity的bindDownLoadStatusController方法</p>
<h4 id="全局下载状态控制器已废弃">2.17.3 全局下载状态控制器（已废弃）</h4>
<p><font color="red">注意：1.9.5版本之后（包含1.9.5），全局下载控制和监听器暂时取消支持。</font></p>
<p><del>SDK为接入方提供全局下载状态控制器，该控制器可以改变信息流广告、Banner广告、插屏广告的下载类广告的下载状态。例如：暂停下载、继续下载、取消下载；</del></p>
<h4 id="全局下载状态控制器接口说明已废弃">2.17.4 全局下载状态控制器接口说明（已废弃）</h4>
<p><font color="red">注意：1.9.5版本之后（包含1.9.5），全局下载控制和监听器暂时取消支持。</font></p>
<div class="sourceCode" id="cb57"><pre class="sourceCode java"><code class="sourceCode java"><a class="sourceLine" id="cb57-1" title="1"><span class="at">@Deprecated</span></a>
<a class="sourceLine" id="cb57-2" title="2"><span class="kw">public</span> <span class="kw">interface</span> TTGlobalAppDownloadController {</a>
<a class="sourceLine" id="cb57-3" title="3">    <span class="co">/**</span></a>
<a class="sourceLine" id="cb57-4" title="4">     <span class="co">*</span> 下载状态控制</a>
<a class="sourceLine" id="cb57-5" title="5">     <span class="co">*</span> 【下载中】调用则会暂停下载</a>
<a class="sourceLine" id="cb57-6" title="6">     <span class="co">*</span> 【暂停中】调用则会开始下载</a>
<a class="sourceLine" id="cb57-7" title="7">     <span class="co">*</span> 【下载完成】调用则会弹出安装页面</a>
<a class="sourceLine" id="cb57-8" title="8">     <span class="co">*</span></a>
<a class="sourceLine" id="cb57-9" title="9">     <span class="co">* </span><span class="an">@param internalStatusKey </span>下载任务SDK内部状态标识，从TTAppDownloadInfo获取</a>
<a class="sourceLine" id="cb57-10" title="10">     <span class="co">*</span> <span class="an">@param id </span>    任务Id，从TTAppDownloadInfo中获取</a>
<a class="sourceLine" id="cb57-11" title="11">     <span class="co">*/</span></a>
<a class="sourceLine" id="cb57-12" title="12">    <span class="dt">void</span> <span class="fu">changeDownloadStatus</span>(<span class="dt">int</span> internalStatusKey, <span class="dt">long</span> id);</a>
<a class="sourceLine" id="cb57-13" title="13"></a>
<a class="sourceLine" id="cb57-14" title="14">    <span class="co">/**</span></a>
<a class="sourceLine" id="cb57-15" title="15">     <span class="co">*</span> 删除下载任务</a>
<a class="sourceLine" id="cb57-16" title="16">     <span class="co">*</span></a>
<a class="sourceLine" id="cb57-17" title="17">     <span class="co">* </span><span class="an">@param id </span>任务id，从TTAppDownloadInfo中获取</a>
<a class="sourceLine" id="cb57-18" title="18">     <span class="co">*/</span></a>
<a class="sourceLine" id="cb57-19" title="19">    <span class="dt">void</span> <span class="fu">removeDownloadTask</span>(<span class="dt">long</span> id);</a>
<a class="sourceLine" id="cb57-20" title="20">}</a></code></pre></div>
<h4 id="接入全局下载状态控制器已废弃">2.17.5 接入全局下载状态控制器（已废弃）</h4>
<p><font color="red">注意：1.9.5版本之后（包含1.9.5），全局下载控制和监听器暂时取消支持。</font></p>
<div class="sourceCode" id="cb58"><pre class="sourceCode java"><code class="sourceCode java"><a class="sourceLine" id="cb58-1" title="1">    <span class="co">//获取下载状态控制器</span></a>
<a class="sourceLine" id="cb58-2" title="2">    <span class="at">@Deprecated</span></a>
<a class="sourceLine" id="cb58-3" title="3">    TTGlobalAppDownloadController appDownloadController = TTAdManager.<span class="fu">getGlobalAppDownloadController</span>(<span class="bu">Context</span> context);</a></code></pre></div>
<p><del>详细示例请看Demo中的AppDownloadService</del></p>
<h4 id="全局下载状态监听器已废弃">2.17.6 全局下载状态监听器（已废弃）</h4>
<p><font color="red">注意：1.9.5版本之后（包含1.9.5），全局下载控制和监听器暂时取消支持。</font></p>
<p><del>SDK针对应用下载广告提供了下载状态监听器，接入方可注册该监听器以监听所有下载状任务状态的变化，监听器支持未下载、下载中、下载暂停、下载失败、下载完成、安装完成的回调。当应用返回桌面时，如果下载还在进行，该监听器依然能收到回调。</del></p>
<h4 id="全局下载状态监听器接口说明已废弃">2.17.7 全局下载状态监听器接口说明（已废弃）</h4>
<p><font color="red">注意：1.9.5版本之后（包含1.9.5），全局下载控制和监听器暂时取消支持。</font></p>
<div class="sourceCode" id="cb59"><pre class="sourceCode java"><code class="sourceCode java"><a class="sourceLine" id="cb59-1" title="1"><span class="at">@Deprecated</span></a>
<a class="sourceLine" id="cb59-2" title="2"><span class="kw">public</span> <span class="kw">interface</span> TTGlobalAppDownloadListener {</a>
<a class="sourceLine" id="cb59-3" title="3">    <span class="co">/**</span></a>
<a class="sourceLine" id="cb59-4" title="4">     <span class="co">*</span> 下载状态更新时回调，多个下载任务会回调多次，下载任务可以用TTAppDownloadInfo<span class="co">.</span>mId区分</a>
<a class="sourceLine" id="cb59-5" title="5">     <span class="co">*</span></a>
<a class="sourceLine" id="cb59-6" title="6">     <span class="co">* </span><span class="an">@param info </span>TTAppDownloadInfo 状态信息</a>
<a class="sourceLine" id="cb59-7" title="7">     <span class="co">*/</span></a>
<a class="sourceLine" id="cb59-8" title="8">    <span class="dt">void</span> <span class="fu">onDownloadActive</span>(TTAppDownloadInfo info);</a>
<a class="sourceLine" id="cb59-9" title="9"></a>
<a class="sourceLine" id="cb59-10" title="10">    <span class="co">/**</span></a>
<a class="sourceLine" id="cb59-11" title="11">     <span class="co">*</span> 下载任务暂停时回调</a>
<a class="sourceLine" id="cb59-12" title="12">     <span class="co">*</span></a>
<a class="sourceLine" id="cb59-13" title="13">     <span class="co">* </span><span class="an">@param info</span></a>
<a class="sourceLine" id="cb59-14" title="14">     <span class="co">*/</span></a>
<a class="sourceLine" id="cb59-15" title="15">    <span class="dt">void</span> <span class="fu">onDownloadPaused</span>(TTAppDownloadInfo info);</a>
<a class="sourceLine" id="cb59-16" title="16"></a>
<a class="sourceLine" id="cb59-17" title="17">    <span class="co">/**</span></a>
<a class="sourceLine" id="cb59-18" title="18">     <span class="co">*</span> 下载任务完成时回调</a>
<a class="sourceLine" id="cb59-19" title="19">     <span class="co">*</span></a>
<a class="sourceLine" id="cb59-20" title="20">     <span class="co">* </span><span class="an">@param info</span></a>
<a class="sourceLine" id="cb59-21" title="21">     <span class="co">*/</span></a>
<a class="sourceLine" id="cb59-22" title="22">    <span class="dt">void</span> <span class="fu">onDownloadFinished</span>(TTAppDownloadInfo info);</a>
<a class="sourceLine" id="cb59-23" title="23"></a>
<a class="sourceLine" id="cb59-24" title="24">    <span class="co">/**</span></a>
<a class="sourceLine" id="cb59-25" title="25">     <span class="co">*</span> 安装完成时回调，不保证一定会回调</a>
<a class="sourceLine" id="cb59-26" title="26">     <span class="co">*</span></a>
<a class="sourceLine" id="cb59-27" title="27">     <span class="co">* </span><span class="an">@param pkgName </span>安装的包名</a>
<a class="sourceLine" id="cb59-28" title="28">     <span class="co">*</span> <span class="an">@param appName </span>安装的应用名</a>
<a class="sourceLine" id="cb59-29" title="29">     <span class="co">*</span> <span class="an">@param id </span>     下载任务的id</a>
<a class="sourceLine" id="cb59-30" title="30">     <span class="co">*</span> <span class="an">@param internalStatusKey </span> 下载任务SDK内部状态标识，仅用于TTGlobalAppDownloadController使用</a>
<a class="sourceLine" id="cb59-31" title="31">     <span class="co">*/</span></a>
<a class="sourceLine" id="cb59-32" title="32">    <span class="dt">void</span> <span class="fu">onInstalled</span>(<span class="bu">String</span> pkgName, <span class="bu">String</span> appName, <span class="dt">long</span> id, <span class="dt">int</span> internalStatusKey);</a>
<a class="sourceLine" id="cb59-33" title="33"></a>
<a class="sourceLine" id="cb59-34" title="34">    <span class="co">/**</span></a>
<a class="sourceLine" id="cb59-35" title="35">     <span class="co">*</span> 下载失败时回调</a>
<a class="sourceLine" id="cb59-36" title="36">     <span class="co">*</span></a>
<a class="sourceLine" id="cb59-37" title="37">     <span class="co">* </span><span class="an">@param info</span></a>
<a class="sourceLine" id="cb59-38" title="38">     <span class="co">*/</span></a>
<a class="sourceLine" id="cb59-39" title="39">    <span class="dt">void</span> <span class="fu">onDownloadFailed</span>(TTAppDownloadInfo info);</a>
<a class="sourceLine" id="cb59-40" title="40">}</a></code></pre></div>
<h4 id="接入全局下载状态监听器已废弃">2.17.8 接入全局下载状态监听器（已废弃）</h4>
<p><font color="red">注意：1.9.5版本之后（包含1.9.5），全局下载控制和监听器暂时取消支持。</font></p>
<p><del>在初始化SDK时，使用TTAdConfig.globalDownloadListener设置全局下载状态监听器</del></p>
<pre><code>@Deprecated
ttAdManager.globalDownloadListener(new AppDownloadStatusListener(context));
</code></pre>
<p><del>详细示例请看Demo中的AppDownloadStatusListener</del></p>
<h4 id="下载状态module已废弃">2.17.9 下载状态Module（已废弃）</h4>
<p><font color="red">注意：1.9.5版本之后（包含1.9.5），全局下载控制和监听器暂时取消支持。</font></p>
<p><del>在TTGlobalAppDownloadListener接口方法中，SDK给开发者提供了下载任务的所有状态信息，包括：下载任务的id，下载任务的总字节数，已经下载的字节数、文件保存的文件名、下载的App名。</del></p>
<p><del><strong>注意：调用TTGlobalAppDownloadController.changeDownloadStatus(int internalStatusKey, long id)时，需要传入mInternalStatusKey、mId</strong></del></p>
<pre><code>@Deprecated
public class TTAppDownloadInfo {
    private long mId;               //下载任务id
    private int mInternalStatusKey; //下载任务SDK内部状态标识，仅用于TTGlobalAppDownloadController使用    
    private long mTotalBytes;       //总字节数
    private long mCurrBytes;        //当前已下载字节数
    private String mFileName;       //保存文件名
    private String mAppName;        //App名

    public long getId() {
        return mId;
    }

    public void setId(long id) {
        mId = id;
    }

    public int getStatus() {
        return mStatus;
    }

    public void setStatus(int status) {
        mStatus = status;
    }

    public long getTotalBytes() {
        return mTotalBytes;
    }

    public void setTotalBytes(long totalBytes) {
        mTotalBytes = totalBytes;
    }

    public long getCurrBytes() {
        return mCurrBytes;
    }

    public void setCurrBytes(long currBytes) {
        this.mCurrBytes = currBytes;
    }

    public String getFileName() {
        return mFileName;
    }

    public void setFileName(String fileName) {
        this.mFileName = fileName;
    }

    public String getAppName() {
        return mAppName;
    }

    public void setAppName(String appName) {
        mAppName = appName;
    }

}

</code></pre>
<h3 id="接入dislike逻辑ttaddislike">3.0 接入Dislike逻辑（TTAdDislike）</h3>
<p>SDK为接入方提供了信息流广告、Banner广告的Dislike逻辑，当用户选择关闭广告时候，会有提示询问用户，包含“不感兴趣”、“看过了”选项供用户选择。该反馈主要用于头条广告对用户端的广告策略，用来优化提升广告的点击率，提升广告效果及合作伙伴的收益。<br />
<strong>注意：如果使用Dislike逻辑，初始化TTAdNative mTTAdNative = ttAdManager.createAdNative(activity)时，参数务必传入activity。</strong></p>
<h4 id="ttaddislike接口说明">3.1 TTAdDislike接口说明</h4>
<p>获得TTFeedAd或TTBannerAd后，调用TTFeedAd.getDislikeDialog()或TTBannerAd.getDislikeDialog()即可获得TTAdDislike对象。DislikeInteractionCallback为用户选择结果回调接口。</p>
<div class="sourceCode" id="cb62"><pre class="sourceCode java"><code class="sourceCode java"><a class="sourceLine" id="cb62-1" title="1"><span class="kw">public</span> <span class="kw">interface</span> TTAdDislike {</a>
<a class="sourceLine" id="cb62-2" title="2">    <span class="co">/**</span></a>
<a class="sourceLine" id="cb62-3" title="3">     <span class="co">*</span> 弹出Dislike Dialog</a>
<a class="sourceLine" id="cb62-4" title="4">     <span class="co">*/</span></a>
<a class="sourceLine" id="cb62-5" title="5">    <span class="dt">void</span> <span class="fu">showDislikeDialog</span>();</a>
<a class="sourceLine" id="cb62-6" title="6"></a>
<a class="sourceLine" id="cb62-7" title="7">    <span class="co">/**</span></a>
<a class="sourceLine" id="cb62-8" title="8">     <span class="co">*</span> 设置dislike选中时的回调</a>
<a class="sourceLine" id="cb62-9" title="9">     <span class="co">*/</span></a>
<a class="sourceLine" id="cb62-10" title="10">    <span class="dt">void</span> <span class="fu">setDislikeInteractionCallback</span>(DislikeInteractionCallback dislikeInteractionCallback);</a>
<a class="sourceLine" id="cb62-11" title="11"></a>
<a class="sourceLine" id="cb62-12" title="12">    <span class="co">/**</span></a>
<a class="sourceLine" id="cb62-13" title="13">     <span class="co">*</span> 暴露给用户，处理dislike选择结果</a>
<a class="sourceLine" id="cb62-14" title="14">     <span class="co">*/</span></a>
<a class="sourceLine" id="cb62-15" title="15">    <span class="kw">interface</span> DislikeInteractionCallback {</a>
<a class="sourceLine" id="cb62-16" title="16"></a>
<a class="sourceLine" id="cb62-17" title="17">        <span class="co">/**</span></a>
<a class="sourceLine" id="cb62-18" title="18">         <span class="co">* </span><span class="an">@param position </span>选择的位置</a>
<a class="sourceLine" id="cb62-19" title="19">         <span class="co">*</span> <span class="an">@param value </span>   选择的内容</a>
<a class="sourceLine" id="cb62-20" title="20">         <span class="co">*/</span></a>
<a class="sourceLine" id="cb62-21" title="21">        <span class="dt">void</span> <span class="fu">onSelected</span>(<span class="dt">int</span> position, <span class="bu">String</span> value);</a>
<a class="sourceLine" id="cb62-22" title="22"></a>
<a class="sourceLine" id="cb62-23" title="23">        <span class="co">/**</span></a>
<a class="sourceLine" id="cb62-24" title="24">         <span class="co">*</span> 点击取消</a>
<a class="sourceLine" id="cb62-25" title="25">         <span class="co">*/</span></a>
<a class="sourceLine" id="cb62-26" title="26">        <span class="dt">void</span> <span class="fu">onCancel</span>();</a>
<a class="sourceLine" id="cb62-27" title="27">    }</a>
<a class="sourceLine" id="cb62-28" title="28">}</a></code></pre></div>
<h4 id="信息流广告接入dislike">3.2 信息流广告接入Dislike</h4>
<p>在获得TTFeedAd后，调用TTFeedAd.getDislikeDialog()获取TTAdDislike对象，然后为该对象设置用户选择结果回调。具体代码示例如下：</p>
<pre><code>//获取到TTFeedAd后，可接入dislike逻辑
final TTAdDislike ttAdDislike = ttFeedAd.getDislikeDialog();
if (ttAdDislike != null) {
      ttAdDislike.setDislikeInteractionCallback(new TTAdDislike.DislikeInteractionCallback() {
          @Override
          public void onSelected(int position, String value) {
                //用户选择了第position条理由，该条理由的内容为value
          }
    
          @Override
          public void onCancel() {
                //用户点击取消按钮
          }
      });
      dislikeIcon.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              ttAdDislike.showDislikeDialog();
          }
      });
}</code></pre>
<h4 id="banner广告接入dislike">3.3 Banner广告接入Dislike</h4>
<ul>
<li>方法一： 使用SDK内置DislikeIcon</li>
</ul>
<div class="sourceCode" id="cb64"><pre class="sourceCode java"><code class="sourceCode java"><a class="sourceLine" id="cb64-1" title="1">mTTAdNative.<span class="fu">loadBannerAd</span>(adSlot, <span class="kw">new</span> TTAdNative.<span class="fu">BannerAdListener</span>() {</a>
<a class="sourceLine" id="cb64-2" title="2"></a>
<a class="sourceLine" id="cb64-3" title="3">    <span class="at">@Override</span></a>
<a class="sourceLine" id="cb64-4" title="4">    <span class="kw">public</span> <span class="dt">void</span> <span class="fu">onError</span>(<span class="dt">int</span> code, <span class="bu">String</span> message) {</a>
<a class="sourceLine" id="cb64-5" title="5">        Toast.<span class="fu">makeText</span>(BannerActivity.<span class="fu">this</span>, <span class="st">&quot;load error : &quot;</span> + code + <span class="st">&quot;, &quot;</span> + message, Toast.<span class="fu">LENGTH_SHORT</span>).<span class="fu">show</span>();</a>
<a class="sourceLine" id="cb64-6" title="6">        mBannerContainer.<span class="fu">setVisibility</span>(<span class="bu">View</span>.<span class="fu">GONE</span>);</a>
<a class="sourceLine" id="cb64-7" title="7">        mTvDownloadText.<span class="fu">setVisibility</span>(<span class="bu">View</span>.<span class="fu">GONE</span>);</a>
<a class="sourceLine" id="cb64-8" title="8">    }</a>
<a class="sourceLine" id="cb64-9" title="9"></a>
<a class="sourceLine" id="cb64-10" title="10">    <span class="at">@Override</span></a>
<a class="sourceLine" id="cb64-11" title="11">    <span class="kw">public</span> <span class="dt">void</span> <span class="fu">onBannerAdLoad</span>(<span class="dt">final</span> TTBannerAd ad) {</a>
<a class="sourceLine" id="cb64-12" title="12">        <span class="co">//省略其他代码，方便阅读</span></a>
<a class="sourceLine" id="cb64-13" title="13"></a>
<a class="sourceLine" id="cb64-14" title="14">        <span class="co">//在banner中显示穿山甲提供的dislike icon</span></a>
<a class="sourceLine" id="cb64-15" title="15">        ad.<span class="fu">setShowDislikeIcon</span>(<span class="kw">new</span> TTAdDislike.<span class="fu">DislikeInteractionCallback</span>() {</a>
<a class="sourceLine" id="cb64-16" title="16">            <span class="at">@Override</span></a>
<a class="sourceLine" id="cb64-17" title="17">            <span class="kw">public</span> <span class="dt">void</span> <span class="fu">onSelected</span>(<span class="dt">int</span> position, <span class="bu">String</span> value) {</a>
<a class="sourceLine" id="cb64-18" title="18">                Toast.<span class="fu">makeText</span>(mContext, <span class="st">&quot;点击 &quot;</span> + value, Toast.<span class="fu">LENGTH_SHORT</span>).<span class="fu">show</span>();</a>
<a class="sourceLine" id="cb64-19" title="19">                mBannerContainer.<span class="fu">setVisibility</span>(<span class="bu">View</span>.<span class="fu">GONE</span>);</a>
<a class="sourceLine" id="cb64-20" title="20">            }</a>
<a class="sourceLine" id="cb64-21" title="21"></a>
<a class="sourceLine" id="cb64-22" title="22">            <span class="at">@Override</span></a>
<a class="sourceLine" id="cb64-23" title="23">            <span class="kw">public</span> <span class="dt">void</span> <span class="fu">onCancel</span>() {</a>
<a class="sourceLine" id="cb64-24" title="24">                Toast.<span class="fu">makeText</span>(mContext, <span class="st">&quot;点击取消 &quot;</span>, Toast.<span class="fu">LENGTH_SHORT</span>).<span class="fu">show</span>();</a>
<a class="sourceLine" id="cb64-25" title="25">            }</a>
<a class="sourceLine" id="cb64-26" title="26">        });</a>
<a class="sourceLine" id="cb64-27" title="27">    }</a>
<a class="sourceLine" id="cb64-28" title="28">});</a>
<a class="sourceLine" id="cb64-29" title="29">}</a></code></pre></div>
<ul>
<li>方法二: 使用自定义的DislikeIcon</li>
</ul>
<div class="sourceCode" id="cb65"><pre class="sourceCode java"><code class="sourceCode java"><a class="sourceLine" id="cb65-1" title="1">mTTAdNative.<span class="fu">loadBannerAd</span>(adSlot, <span class="kw">new</span> TTAdNative.<span class="fu">BannerAdListener</span>() {</a>
<a class="sourceLine" id="cb65-2" title="2">    <span class="at">@Override</span></a>
<a class="sourceLine" id="cb65-3" title="3">    <span class="kw">public</span> <span class="dt">void</span> <span class="fu">onError</span>(<span class="dt">int</span> code, <span class="bu">String</span> message) {</a>
<a class="sourceLine" id="cb65-4" title="4">        Toast.<span class="fu">makeText</span>(BannerActivity.<span class="fu">this</span>, <span class="st">&quot;load error : &quot;</span> + code + <span class="st">&quot;, &quot;</span> + message, Toast.<span class="fu">LENGTH_SHORT</span>).<span class="fu">show</span>();</a>
<a class="sourceLine" id="cb65-5" title="5">        mBannerContainer.<span class="fu">setVisibility</span>(<span class="bu">View</span>.<span class="fu">GONE</span>);</a>
<a class="sourceLine" id="cb65-6" title="6">        mTvDownloadText.<span class="fu">setVisibility</span>(<span class="bu">View</span>.<span class="fu">GONE</span>);</a>
<a class="sourceLine" id="cb65-7" title="7">    }</a>
<a class="sourceLine" id="cb65-8" title="8">    </a>
<a class="sourceLine" id="cb65-9" title="9">    <span class="at">@Override</span></a>
<a class="sourceLine" id="cb65-10" title="10">    <span class="kw">public</span> <span class="dt">void</span> <span class="fu">onBannerAdLoad</span>(<span class="dt">final</span> TTBannerAd ad) {</a>
<a class="sourceLine" id="cb65-11" title="11">      <span class="co">//省略其他代码，方便阅读</span></a>
<a class="sourceLine" id="cb65-12" title="12">    </a>
<a class="sourceLine" id="cb65-13" title="13">        <span class="co">//获得穿山甲dislike dialog 接入方可以在自己的dislike icon 按钮中设置 mTTAdDislike.showDislikeDialog();</span></a>
<a class="sourceLine" id="cb65-14" title="14">    </a>
<a class="sourceLine" id="cb65-15" title="15">        mTTAdDislike = ad.<span class="fu">getDislikeDialog</span>(<span class="kw">new</span> TTAdDislike.<span class="fu">DislikeInteractionCallback</span>() {</a>
<a class="sourceLine" id="cb65-16" title="16">                <span class="at">@Override</span></a>
<a class="sourceLine" id="cb65-17" title="17">                <span class="kw">public</span> <span class="dt">void</span> <span class="fu">onSelected</span>(<span class="dt">int</span> position, <span class="bu">String</span> value) {</a>
<a class="sourceLine" id="cb65-18" title="18">                    Toast.<span class="fu">makeText</span>(mContext, <span class="st">&quot;点击 &quot;</span> + value, Toast.<span class="fu">LENGTH_SHORT</span>).<span class="fu">show</span>();</a>
<a class="sourceLine" id="cb65-19" title="19">                }</a>
<a class="sourceLine" id="cb65-20" title="20">    </a>
<a class="sourceLine" id="cb65-21" title="21">                <span class="at">@Override</span></a>
<a class="sourceLine" id="cb65-22" title="22">                <span class="kw">public</span> <span class="dt">void</span> <span class="fu">onCancel</span>() {</a>
<a class="sourceLine" id="cb65-23" title="23">                    Toast.<span class="fu">makeText</span>(mContext, <span class="st">&quot;点击取消 &quot;</span>, Toast.<span class="fu">LENGTH_SHORT</span>).<span class="fu">show</span>();</a>
<a class="sourceLine" id="cb65-24" title="24">                }</a>
<a class="sourceLine" id="cb65-25" title="25">            });</a>
<a class="sourceLine" id="cb65-26" title="26">        <span class="kw">if</span> (mTTAdDislike != <span class="kw">null</span>) {</a>
<a class="sourceLine" id="cb65-27" title="27">            XXX.<span class="fu">setOnClickListener</span>(<span class="kw">new</span> <span class="bu">View</span>.<span class="fu">OnClickListener</span>() {</a>
<a class="sourceLine" id="cb65-28" title="28">                <span class="at">@Override</span></a>
<a class="sourceLine" id="cb65-29" title="29">                <span class="kw">public</span> <span class="dt">void</span> <span class="fu">onClick</span>(<span class="bu">View</span> v) {</a>
<a class="sourceLine" id="cb65-30" title="30">                    mTTAdDislike.<span class="fu">showDislikeDialog</span>();</a>
<a class="sourceLine" id="cb65-31" title="31">                }</a>
<a class="sourceLine" id="cb65-32" title="32">            });</a>
<a class="sourceLine" id="cb65-33" title="33">        }</a>
<a class="sourceLine" id="cb65-34" title="34">    }</a>
<a class="sourceLine" id="cb65-35" title="35">});</a></code></pre></div>
<p>接入Dislike的具体示例详见Demo中的FeedListActivity及BannerActivity</p>
<p>注：目前FeedListActivity的dislike使用方式已变更为自定义dislike</p>
<h4 id="自定义dislike对话框使用说明">3.4 自定义dislike对话框使用说明</h4>
<p>dislike对话框的使用可以有两种方式：1sdk默认自带的对话框、2开发者自定义dislike样式。</p>
<p>使用接口详见：</p>
<ol type="1">
<li>默认对话框：TTFeedAd.getDislikeDialog(Activity activity)</li>
<li>自定义样式对话框：TTFeedAd.getDislikeDialog(TTDislikeDialogAbstract dialog)</li>
</ol>
<p>重点注意：</p>
<ol type="1">
<li>对话框必须继承：TTDislikeDialogAbstract</li>
<li>列表选择view必须使用：TTDislikeListView</li>
</ol>
<p>具体使用方式详见demo：FeedListActivity#MyAdapter#bindDislikeCustom()</p>
<p>TTDislikeDialogAbstract抽象方法说明：</p>
<div class="sourceCode" id="cb66"><pre class="sourceCode java"><code class="sourceCode java"><a class="sourceLine" id="cb66-1" title="1"><span class="kw">public</span> <span class="kw">abstract</span> <span class="kw">class</span> TTDislikeDialogAbstract <span class="kw">extends</span> <span class="bu">Dialog</span> {</a>
<a class="sourceLine" id="cb66-2" title="2"></a>
<a class="sourceLine" id="cb66-3" title="3">    <span class="co">/**</span></a>
<a class="sourceLine" id="cb66-4" title="4">     <span class="co">*</span> 布局view id</a>
<a class="sourceLine" id="cb66-5" title="5">     <span class="co">*</span></a>
<a class="sourceLine" id="cb66-6" title="6">     <span class="co">* </span><span class="an">@return </span>id</a>
<a class="sourceLine" id="cb66-7" title="7">     <span class="co">*/</span></a>
<a class="sourceLine" id="cb66-8" title="8">    <span class="kw">public</span> <span class="kw">abstract</span> <span class="dt">int</span> <span class="fu">getLayoutId</span>();</a>
<a class="sourceLine" id="cb66-9" title="9"></a>
<a class="sourceLine" id="cb66-10" title="10">    <span class="co">/**</span></a>
<a class="sourceLine" id="cb66-11" title="11">     <span class="co">*</span> 获取listview所有id，这些listview必须继承自TTDislikeListView</a>
<a class="sourceLine" id="cb66-12" title="12">     <span class="co">*</span></a>
<a class="sourceLine" id="cb66-13" title="13">     <span class="co">* </span><span class="an">@return </span>listview id</a>
<a class="sourceLine" id="cb66-14" title="14">     <span class="co">*/</span></a>
<a class="sourceLine" id="cb66-15" title="15">    <span class="kw">public</span> <span class="kw">abstract</span> <span class="dt">int</span>[] <span class="fu">getTTDislikeListViewIds</span>();</a>
<a class="sourceLine" id="cb66-16" title="16"></a>
<a class="sourceLine" id="cb66-17" title="17">    <span class="co">/**</span></a>
<a class="sourceLine" id="cb66-18" title="18">     <span class="co">*</span> 布局参数，可以为null</a>
<a class="sourceLine" id="cb66-19" title="19">     <span class="co">*</span></a>
<a class="sourceLine" id="cb66-20" title="20">     <span class="co">* </span><span class="an">@return </span>参数</a>
<a class="sourceLine" id="cb66-21" title="21">     <span class="co">*/</span></a>
<a class="sourceLine" id="cb66-22" title="22">    <span class="kw">public</span> <span class="kw">abstract</span> ViewGroup.<span class="fu">LayoutParams</span> <span class="fu">getLayoutParams</span>();</a>
<a class="sourceLine" id="cb66-23" title="23"></a>
<a class="sourceLine" id="cb66-24" title="24">}</a></code></pre></div>
<h2 id="参考">4.参考</h2>
<h3 id="sdk错误码">4.1 SDK错误码</h3>
<table>
<thead>
<tr class="header">
<th>错误码</th>
<th>说明</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td>20000</td>
<td>成功</td>
</tr>
<tr class="even">
<td>40000</td>
<td>http content type错误</td>
</tr>
<tr class="odd">
<td>40001</td>
<td>http request pb错误</td>
</tr>
<tr class="even">
<td>40002</td>
<td>source_type=‘app’, 请求app不能为空</td>
</tr>
<tr class="odd">
<td>40003</td>
<td>source_type=‘wap’, 请求wap不能为空</td>
</tr>
<tr class="even">
<td>40004</td>
<td>广告位不能为空</td>
</tr>
<tr class="odd">
<td>40005</td>
<td>广告位尺寸不能为空</td>
</tr>
<tr class="even">
<td>40006</td>
<td>广告位ID不合法</td>
</tr>
<tr class="odd">
<td>40007</td>
<td>广告数量错误</td>
</tr>
<tr class="even">
<td>40008</td>
<td>图片尺寸错误</td>
</tr>
<tr class="odd">
<td>40009</td>
<td>媒体ID不合法</td>
</tr>
<tr class="even">
<td>40010</td>
<td>媒体类型不合法</td>
</tr>
<tr class="odd">
<td>40011</td>
<td>广告类型不合法</td>
</tr>
<tr class="even">
<td>40012</td>
<td>媒体接入类型不合法，已废弃</td>
</tr>
<tr class="odd">
<td>40013</td>
<td>代码位id小于9亿，但是adType不是开屏</td>
</tr>
<tr class="even">
<td>40014</td>
<td>redirect参数不正确</td>
</tr>
<tr class="odd">
<td>40015</td>
<td>媒体整改超过期限，请求非法</td>
</tr>
<tr class="even">
<td>40016</td>
<td>slot_id 与 app_id对应关系不合法</td>
</tr>
<tr class="odd">
<td>40017</td>
<td>媒体接入类型不合法 API/SDK</td>
</tr>
<tr class="even">
<td>40018</td>
<td>媒体包名与录入不一致</td>
</tr>
<tr class="odd">
<td>40019</td>
<td>媒体配置adtype和请求不一致</td>
</tr>
<tr class="even">
<td>40020</td>
<td>开发注册新上线广告位超出日请求量限制</td>
</tr>
<tr class="odd">
<td>40021</td>
<td>apk签名sha1值与媒体平台录入不一致</td>
</tr>
<tr class="even">
<td>40022</td>
<td>媒体请求素材是否原生与媒体平台录入不一致</td>
</tr>
<tr class="odd">
<td>40023</td>
<td>os字段填的不对</td>
</tr>
<tr class="even">
<td>40024</td>
<td>sdk 版本过低不返回广告</td>
</tr>
<tr class="odd">
<td>40025</td>
<td>引入SDK包不完整，建议校验SDK包完整性或联系技术支持</td>
</tr>
<tr class="even">
<td>40029</td>
<td>模板广告请求使用了错误的方式，见下方FAQ说明</td>
</tr>
<tr class="odd">
<td>50001</td>
<td>服务器错误</td>
</tr>
<tr class="even">
<td>60001</td>
<td>show event处理错误</td>
</tr>
<tr class="odd">
<td>60002</td>
<td>click event处理错误</td>
</tr>
<tr class="even">
<td>60007</td>
<td>激励视频验证服务器异常或处理失败</td>
</tr>
<tr class="odd">
<td>-1</td>
<td>数据解析失败</td>
</tr>
<tr class="even">
<td>-2</td>
<td>网络错误</td>
</tr>
<tr class="odd">
<td>-3</td>
<td>解析数据没有ad</td>
</tr>
<tr class="even">
<td>-4</td>
<td>返回数据缺少必要字段</td>
</tr>
<tr class="odd">
<td>-5</td>
<td>bannerAd加载图片失败</td>
</tr>
<tr class="even">
<td>-6</td>
<td>插屏广告图片加载失败</td>
</tr>
<tr class="odd">
<td>-7</td>
<td>开屏广告图片加载失败</td>
</tr>
<tr class="even">
<td>-8</td>
<td>频繁请求</td>
</tr>
<tr class="odd">
<td>-9</td>
<td>请求实体为空</td>
</tr>
<tr class="even">
<td>-10</td>
<td>缓存解析失败</td>
</tr>
<tr class="odd">
<td>-11</td>
<td>缓存过期</td>
</tr>
<tr class="even">
<td>-12</td>
<td>缓存中没有开屏广告</td>
</tr>
<tr class="odd">
<td>101</td>
<td>渲染结果数据解析失败</td>
</tr>
<tr class="even">
<td>102</td>
<td>主模板无效</td>
</tr>
<tr class="odd">
<td>103</td>
<td>模板差量无效</td>
</tr>
<tr class="even">
<td>104</td>
<td>物料数据异常</td>
</tr>
<tr class="odd">
<td>105</td>
<td>模板数据解析异常</td>
</tr>
<tr class="even">
<td>106</td>
<td>渲染异常</td>
</tr>
<tr class="odd">
<td>107</td>
<td>渲染超时未回调</td>
</tr>
</tbody>
</table>
<h3 id="sdk多进程支持">4.2 SDK多进程支持</h3>
<p>如果您的应用需要支持多进程，请务必设置TTAdConfig.supportMultiProcess(true)。</p>
<p>确认app多进程支持判断方法：1穿山甲sdk初始化、2穿山甲广告获取、3穿山甲广告展示，这三个关键点的调用在不同进程，否则即为单进程。</p>
<p>如非必要尽量不要使用多进程开关，多进程效率不如单进程高。</p>
<h3 id="sdk打包为独立插件">4.3 SDK打包为独立插件</h3>
<p>如果您想把SDK打包到您的独立插件中，请确认您所使用的插件方案是否支持SDK内使用RemoteView弹出notification，如不支持，请设置TTAdConfig.allowShowNotify(false)，然后设置TTAdConfig.globalDownloadListener(TTGlobalAppDownloadListener listener)，以便监听下载进度状态。</p>
<h3 id="主题配置">4.4 主题配置</h3>
<p>本SDK支持用户自定义下载删除弹窗、非Wifi下载提示弹窗的主题和落地页titleBar的主题。</p>
<h4 id="下载删除弹窗主题配置">4.4.1 下载删除弹窗主题配置</h4>
<p>用户可在styles.xml里覆盖下载删除弹窗、非Wifi下载提示弹窗的主题。</p>
<pre><code>&lt;!—配置下载删除弹窗的主题 默认为Theme.DeviceDefault.Light.Dialog&quot; —&gt;
&lt;style name=&quot;Theme.Dialog.TTDownload&quot; parent=&quot;Theme.AppCompat.Light.Dialog&quot;&gt;
        &lt;item name=&quot;windowNoTitle&quot;&gt;android:attr/windowNoTitle&lt;/item&gt;
        &lt;item name=&quot;android:windowBackground&quot;&gt;@color/white&lt;/item&gt;
&lt;/style&gt;</code></pre>
<h4 id="落地页titlebar主题配置">4.4.2 落地页titleBar主题配置</h4>
<p>通过TTAdConfig可设置落地页的主题，目前支持落地页无titleBar（TITLE_BAR_THEME_NO_TITLE_BAR）、titleBar亮色主题(TTAdConstant.TITLE_BAR_THEME_LIGHT)，titleBar暗色主题(TTAdConstant.TITLE_BAR_THEME_DARK)三种。</p>
<pre><code>TTAdConfig.titleBarTheme(TTAdConstant.TITLE_BAR_THEME_DARK);</code></pre>
<h3 id="常见问题">4.5 常见问题</h3>
<p>1.全局信息：</p>
<ul>
<li>调用TTAdManager.createAdNative(Context context)设置全局信息时，请务必保证传入的context为activity，否则会影响应用下载广告的下载。</li>
</ul>
<p>2.信息流广告：</p>
<ul>
<li>在创建信息流创意广告时请务必调用registerViewForInteraction(ViewGroup container, List clickViews, List creativeViews, AdInteractionListener listener)，否则会影响广告的计费及交互功能；</li>
<li>在调用registerViewForInteraction(ViewGroup container, List clickViews, List creativeViews, AdInteractionListener listener)方法时，如果clickViews、creativeViews中包含了相同的View，该View只会回调创意点击的回调。</li>
</ul>
<p>3.Andriod 7.0及以上 用户点击了“点击安装”后没有反应，或者下载完成后没有调起安装界面。</p>
<ul>
<li>请按照接入文档中适配Android7.0的方法去接入。并且确保support-v4包的版本为24.2.0及以上。</li>
</ul>
<p>4.如何区分落地页广告还是app下载广告？</p>
<ul>
<li>在广告的交互类型中，在浏览器内打开 （普通类型）、落地页（普通类型）、应用下载广告可以区分是落地页广告还是app下载广告。</li>
</ul>
<p>5.信息流视频广告如何记录展示？</p>
<ul>
<li>与信息流逻辑一致，在屏幕展现即可记录一个show</li>
</ul>
<p>6.资源混淆问题：如果您的应用对资源也进行混淆（如andResGuard），请不要混淆穿山甲的任何资源，防止资源找不到崩溃，穿山甲的资源清单请咨询技术支持</p>
<p>7.40029错误码，原因有以下两种 - 1. SDK版本低：您使用的sdk版本不得低于2.5.0.0，麻烦升级到平台最新版本sdk。 - 2. 接口使用错误：创建的代码位类型是模板渲染/非模板渲染，但是请求方法是非模板渲染/模板渲染的方法。解决办法：使用模板渲染的方法去请求模板渲染类型或者使用非模板渲染的方法去请求非模板类型的广告，如果代码位在平台上是模板渲染，可以参考文档中个性化模板XX广告的部分，demo中参考带有express部分的代码。如果代码位不是模板渲染，则不要调用含有express字样的接口。 - 参考文档：https://partner.oceanengine.com/doc?id=5dd0fe716b181e00112e3eb8</p>
<p>8.其他问题请咨询穿山甲相关人员。</p>
</body>
</html>
